1、在父类模块的pom 文件添加 eureka相关依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
2、在eureka模块的application.yml文件添加 eureka相关的配置
eureka.instance.hostname=eureka7001.com
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.service-url.defaultZone=http://eureka7001.com:5060/eureka/
3、在eureka模块的启动类上添加@EnableEurekaServer注解,启动 eureka服务注册中心
@EnableEurekaServer
@SpringBootApplication
public class SpringbootdemoEurekaApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootdemoEurekaApplication.class, args);
}
}
4、 在各服务模块的application.yml文件添加eureka相关配置
eureka.client.fetch-registry=true
eureka.client.register-with-eureka=true
eureka.client.service-url.defaultZone=http://localhost:${eureka模块名}/eureka
5、在各服务模块的启动类添加@EnableEurekaClient或@EnableDiscoveryClient注解,配置Eureka的客户端
@SpringBootApplication
@EnableEurekaClient
public class SpringbootdemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootdemoProvideApplication.class, args);
}
}
6、启动eureka模块,页面访问http://${ip}:${eureka模块名},出现以下画面说明eureka启动成功
7、启动服务模块,页面再次访问http://${ip}:${eureka模块名},出现以下画面说明服务注册成功