4. Spring Cloud 之服务治理 - Eureka服务发现-生产者

Spring Cloud 之服务治理 - Eureka服务发现-生产者

实现服务发现非常容易,只需要如下几步:
1.添加依赖

compile "org.springframework.cloud:spring-cloud-starter-eureka:${cloud_config}"

2.添加注解

@EnableEurekaClient

3.稍作配置
在应用上下文(一般是application.yaml)中配置Eureka Server地址

eureka:
  client:
    service-url:
      defaultZone: http://localhost:9871/eureka

测试代码

    @Autowired
    var discoveryClient: DiscoveryClient? = null

    @RequestMapping("/say")
    fun say(): String {
        return "Services: " + discoveryClient!!.services
    }

4.启动服务,大功告成

你可能感兴趣的:(4. Spring Cloud 之服务治理 - Eureka服务发现-生产者)