首页  

springcloud DiscoveryClient使用说明     所属分类 springcloud 浏览量 1236
@Autowired
private DiscoveryClient discoveryClient;


   @GetMapping(value = "/discoveryInfo")
    public Map<String,Object> discoveryInfo() throws Exception {
    	Map<String,Object> map = new HashMap<String,Object>();
    	List<ServiceInstance> list = discoveryClient.getInstances("provider");
    	List<String> services = discoveryClient.getServices();
    	map.put("serviceInstances",list);
    	map.put("services",services);

    	return map;
    }
 
注意类型 DiscoveryClient 类型
正确的类型
org.springframework.cloud.client.discovery.DiscoveryClient

错误的类型
com.netflix.discovery.DiscoveryClient

Field discoveryClient in dyyx.HelloController required a bean of type 'com.netflix.discovery.DiscoveryClient' that could not be found.
The injection point has the following annotations:
	- @org.springframework.beans.factory.annotation.Autowired(required=true)

http://127.0.0.1:9032/discoveryInfo

@EnableDiscoveryClient 与 @EnableEurekaClient区别
spring cloud 中 支持多种服务发现
注册中心使用eureka,推荐@EnableEurekaClient,其他的注册中心,推荐使用@EnableDiscoveryClient。


从公司到家里后ip换了,导致 consumer 端调用失败 ,需要重启provider重新注册

上一篇     下一篇
springboot2 actuator 使用

springboot2获取web端口

springboot2微服务实例

maven知识点整理

springboot打包成可执行jar

springboot打包排除配置文件