基本架构:
注册中心是一个EurekaServer,在Spring Boot启动类上添加注解@EnableEurekaServer,需要添加下面的依赖。
<!-- Eureka服务端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
服务的消费者和提供者都是属于客户端(client),在Spring Boot启动类上添加注解@EnableDiscoveryClient,需要添加依赖:
<!-- Eureka客户端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
作为消费方,可以使用下面的方式调用:
@Autowired
private RestTemplate restTemplate;
@Autowired
p