sd1:创建一个像这样的项目,下面有很多子模块,子模块需要继承父模块的pom文件
2:引入依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--引入consul client依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
<!--健康检查依赖 actuator-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--Open Feign依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
注意:我这里是根据consul为注册中心依赖。启动consul
3:然后我们配置好application.properties文件
server.port=8087
# 指定服务名称(不区分大小写)
spring.application.name=product
# consul server 服务注册地址
spring.cloud.consul.host=localhost
spring.cloud.consul.port=8500
# 执行注册当前服务的服务名称 默认: ${spring.application.name}
spring.cloud.consul.discovery.service-name=${spring.application.name}
4:在启动类上加上注解
5:查看是否有注册成功:输入localhost:8500
我们可以看到这里已经有一个product的模块服务,说明服务注册中已经将刚才的模块注册进来了