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>
