文章目录
- 依赖关键
- 主要的程序
- 启动文件
- 配置文件bootstrap.yml
- 依赖文件
- nacos配置中心上的文件截图
- 启动成功截图
- 参考文档
依赖关键
- SpringBoot版本和com.alibaba.cloud版本需要对应,不然会程序会启动失败
- 作者使用的版本
SpringBoot: 2.1.6.RELEASE
alibabacloud: 2.1.2.RELEASE
主要的程序
启动文件
package com.example.user;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* @author ljj
* @date 2023/8/25 11:15
* @desc
*/
@SpringBootApplication
@EnableDiscoveryClient
public class UserApplication {
public static void main(String[] args) {
SpringApplication.run(UserApplication.class, args);
}
}
配置文件bootstrap.yml
server:
port: 8080
spring:
application:
name: user-test
namespace: test_project
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
profiles:
active: prod
cloud:
nacos:
discovery:
server-addr: localhost:8848
username: nacos
password: nacos
#只能填id,不能填 namespace的名字
namespace: test_project
config:
name: ${spring.application.name}-${spring.profiles.active}
server-addr: localhost:8848
username: nacos
password: nacos
#只能填id,不能填 namespace的名字
namespace: test_project
file-extension: yml
依赖文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>test_project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>user</module>
<module>order</module>
<module>product</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>
nacos配置中心上的文件截图
启动成功截图
参考文档
- Spring cloud alibaba 版本对应关系及说明