1. "springboot automatic assembly of Redis" built by springcloud microservice architecture
Table of contents
1. The project introduces the nacos registry maven configuration
2. The project startup class is added to enable the registration center
3. Configure the registration center
4. Start the nacos registration center and start the project
1. The project introduces the nacos registry maven configuration
Add Nacos configuration to lilock-framework pom
<!-- nacos 版本号 <nacos.version>2.1.0.RELEASE</nacos.version> -->
<!-- nacos配置-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>${nacos.version}</version>
</dependency>
2. Introduce the nacos registration center in the application project pom.xml
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
3. The project startup class is added to enable the registration center
package lilock.cn.user;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication(scanBasePackages = {"lilock.cn.*"})
@EnableConfigurationProperties
@EnableDiscoveryClient //开启注册中心发现
public class UserApplication {
public static void main(String[] args) {
SpringApplication.run(UserApplication.class,args);
}
}
4. Configure the registration center
spring:
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848 #nacos地址加端口
namespace: dev #namespace 环境
register-enabled: true #开启自动注册
group: DEFAULT_GROUP
application:
name: lilock-service-user