@RestController public class ConsumerController { @Autowired private RestTemplate restTemplate; private static final String APPLICATION_NAME = "http://springcloud"; @RequestMapping("/list") public String list() { return restTemplate.getForObject(APPLICATION_NAME + "/get", String.class); } }
@Configuration public class ConfigBean { @Bean @LoadBalanced public RestTemplate getRestTemplate() { return new RestTemplate(); } }
server: port: 9000 eureka: client: service-url: defaultZone: http://eureka7000:7000/eureka/,http://eureka7001:7001/eureka/,http://eureka7002:7002/eureka/ register-with-eureka: false fetch-registry: false instance: prefer-ip-address: true
这句配置的大概意思是不从eureka注册中心获取服务列表,默认为true,这里配置为false所以消费者不从注册中心获取服务列表,所以找不到注册中心的服务
fetch-registry: false
消费者配置文件取消上面那句配置