1、下载nacos服务,将cluster.conf文件中的ip设置成当前电脑的ip,端口号设置8848,启动服务
2、在每个启动类上加注解
@EnableDiscoveryClient
3、在application.yml文件中加入配置
spring: cloud: nacos: discovery: server-addr: 127.0.0.1:8848 //本地+之前设置的端口号 application: name: engoal-approval //服务的名称
4、在common公共服务中引入依赖
<dependencies> <!-- 服务注册/发现--> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <exclusions> <exclusion> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-ribbon</artifactId> </exclusion> </exclusions> </dependency>
//因为新版本服务注册不带这个jar,所以要单独引用 <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-loadbalancer</artifactId> <version>2.2.1.RELEASE</version> </dependency> <!-- 配置中心来做配置管理--> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>2.1.4.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>