一,服务提供者模块引用EurekaClient依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
这里要注意一定要添加 spring-cloud-starter-eureka 依赖,不然注册中心会找不到服务提供者
二,修改yml 配置文件添加eureka 信息
eureka:
client:
service-url:
defaultZone: http://localhost:9003/eureka/
instance:
prefer-ip-address: true
instance-id: ${spring.cloud.client.ip-address}:${server.port} #向注册中心中注册服务id
三,修改服务提供者启动类
添加@EnableDiscoverClient
@SpringBootApplication
@EntityScan("com.zjk.product.entity")
//激活eurekaClient
@EnableDiscoveryClient
public class ProductApplication {
public static void main(String[] args) {
SpringApplication.run(ProductApplication.class,args);
}
}