服务B要请求服务A,一种方式是直接配置服务A的地址。
那么如何从注册中心获取这个服务呢?
网上有很多例子
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
spring:
application:
name: config-client
cloud:
config:
label: master
profile: dev
# uri: http://localhost:8888/
discovery:
enabled: true
serviceId: config-server
management:
security:
enabled: false
server:
port: 8881
按例子中的配置,进行测试,发现启动失败,报一个DiscoveryClient没有定义。
各种查,各种试,最后在启动 类上加了一个 注解搞定。
@EnableEurekaClient
同时增加一个pom依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>