Spring Cloud 之服務(wù)治理 - Eureka服務(wù)發(fā)現(xiàn)-生產(chǎn)者
實(shí)現(xiàn)服務(wù)發(fā)現(xiàn)非常容易,只需要如下幾步:
1.添加依賴
compile "org.springframework.cloud:spring-cloud-starter-eureka:${cloud_config}"
2.添加注解
@EnableEurekaClient
3.稍作配置
在應(yīng)用上下文(一般是application.yaml)中配置Eureka Server
地址
eureka:
client:
service-url:
defaultZone: http://localhost:9871/eureka
測(cè)試代碼
@Autowired
var discoveryClient: DiscoveryClient? = null
@RequestMapping("/say")
fun say(): String {
return "Services: " + discoveryClient!!.services
}
4.啟動(dòng)服務(wù)挚躯,大功告成