This chapter explains how to change springboot to springcloud project without changing the original business and use nacos as the registration center
First download the nacos registration center on the official website. The startup.cmd file in the bin directory is the startup command. The default port number is 8888
Next, modify the original project dependencies
Add the springcloud dependency version in the parent dependency module. If there is no parent dependency, it is also specified in the project directly.
Specify the version first
<properties>
<cloud.version>Hoxton.RELEASE</cloud.version>
<alibaba.version>2.2.0.RELEASE</alibaba.version>
<!--原有项目代码-->
</properties>
add dependencies
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Add nacos dependencies to subprojects
<!-- 服务注册 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
Startup class annotation
@EnableDiscoveryClient
Add in the application configuration file
Specify the naocs address, and the server name
spring:
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8888
application:
name: lzq-v587
After starting the project at this time, after starting naocs, log in to the nacos website
http://localhost:8888/nacos ; both account and password are nacos
You can see the current service in the service list; nacos is lazy loaded, you need to access the service first, and it will be displayed in naocs