【springcloud】Eureka 服务提供者 增加服务暴漏

版权声明:本人博客欢迎转载,但是请表明原链接和出处! https://blog.csdn.net/Phone_1070333541/article/details/87711521

一、Controller 中添加一下代码

    @Autowired
    private DiscoveryClient client;
    
	@RequestMapping(value = "/discovery", method = RequestMethod.GET)
	public Object discovery()
	{
		List<String> list = client.getServices();
		System.out.println("**********" + list);

		List<ServiceInstance> srvList = client.getInstances("springcloud-dept"); // 服务名
		for (ServiceInstance element : srvList) {
			System.out.println(element.getServiceId() + "\t" + element.getHost() + "\t" + element.getPort() + "\t"
					+ element.getUri());
		}
		return this.client;

	}

2. 启动类中增加注解

@EnableDiscoveryClient //服务发现

3. 启动访问

http://localhost:8001/dept/discovery

猜你喜欢

转载自blog.csdn.net/Phone_1070333541/article/details/87711521
今日推荐