feat(springboot3): 添加 RefreshScope 自动配置支持
- 新增 KenaitoRefreshAutoConfiguration 类,实现 ApplicationContextAware - 更新 spring.factories,注册 EnableAutoConfiguration - 与 Spring Boot 2 客户端保持一致,支持 @Value 和 @ConfigurationProperties 动态刷新
This commit is contained in:
@@ -1,64 +0,0 @@
|
||||
# kenaito-conf-springboot3-client-demo
|
||||
|
||||
配置中心 Spring Boot 3 客户端示例项目。
|
||||
|
||||
## 环境要求
|
||||
|
||||
- **JDK 17 或更高版本**(Spring Boot 3 最低要求)
|
||||
- Maven 3.6+
|
||||
|
||||
## 配置说明
|
||||
|
||||
在 `application.properties` 中配置:
|
||||
|
||||
```properties
|
||||
# 配置中心地址
|
||||
kenaito.config.server=http://localhost:8080
|
||||
kenaito.config.appName=demo
|
||||
kenaito.config.env=dev
|
||||
kenaito.config.version=latest
|
||||
kenaito.config.profile=dev
|
||||
```
|
||||
|
||||
## 运行步骤
|
||||
|
||||
1. 确保已安装 JDK 17+:
|
||||
```bash
|
||||
java -version
|
||||
```
|
||||
|
||||
2. 先安装 kenaito-conf-springboot3-client 到本地 Maven 仓库:
|
||||
```bash
|
||||
cd E:\SelfDev\Gitea2026\kenaito-conf\kenaito-conf-springboot3-client
|
||||
mvn clean install -DskipTests
|
||||
```
|
||||
|
||||
3. 运行示例项目:
|
||||
```bash
|
||||
cd E:\SelfDev\Gitea2026\kenaito-conf\kenaito-conf-springboot3-client-demo
|
||||
mvn spring-boot:run
|
||||
```
|
||||
|
||||
4. 访问测试:
|
||||
```bash
|
||||
curl http://localhost:8082/
|
||||
```
|
||||
|
||||
## 配置优先级
|
||||
|
||||
远程配置 > 本地配置
|
||||
|
||||
在配置中心添加应用 `demo` 的配置后,远程配置会覆盖本地同名配置。
|
||||
|
||||
## 与 Spring Boot 2 Demo 的区别
|
||||
|
||||
| 项目 | Spring Boot 版本 | JDK 版本 | 端口 |
|
||||
|------|------------------|----------|------|
|
||||
| kenaito-conf-springboot2-client-demo | 2.7.18 | 1.8+ | 8081 |
|
||||
| kenaito-conf-springboot3-client-demo | 3.2.5 | 17+ | 8082 |
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 当前环境只有 JDK 11,无法运行此项目
|
||||
- 需要安装 JDK 17+ 后才能编译和运行
|
||||
- 如果需要在 JDK 11 环境测试,请使用 kenaito-conf-springboot2-client-demo
|
||||
@@ -1,51 +0,0 @@
|
||||
<?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>cn.odboy</groupId>
|
||||
<artifactId>kenaito-conf-springboot3-client-demo</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>kenaito-conf-springboot3-client-demo</name>
|
||||
<description>Demo project for kenaito-conf Spring Boot 3 client</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.2.5</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</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>
|
||||
|
||||
<!-- kenaito-conf springboot3 client -->
|
||||
<dependency>
|
||||
<groupId>cn.odboy</groupId>
|
||||
<artifactId>kenaito-conf-springboot3-client</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
package cn.odboy.demo;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
public class ConfigController {
|
||||
|
||||
@Value("${app.name:unknown}")
|
||||
private String appName;
|
||||
|
||||
@Value("${app.version:unknown}")
|
||||
private String appVersion;
|
||||
|
||||
@Value("${db.url:unknown}")
|
||||
private String dbUrl;
|
||||
|
||||
@Value("${db.username:unknown}")
|
||||
private String dbUsername;
|
||||
|
||||
@Value("${custom.config1:unknown}")
|
||||
private String customConfig1;
|
||||
|
||||
@GetMapping("/")
|
||||
public Map<String, Object> index() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("appName", appName);
|
||||
result.put("appVersion", appVersion);
|
||||
result.put("dbUrl", dbUrl);
|
||||
result.put("dbUsername", dbUsername);
|
||||
result.put("customConfig1", customConfig1);
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/health")
|
||||
public String health() {
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package cn.odboy.demo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DemoApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=\
|
||||
cn.odboy.confcenter.springboot.KenaitoEnvironmentInitializer
|
||||
@@ -1,21 +0,0 @@
|
||||
# Server
|
||||
server.port=8081
|
||||
|
||||
# Application
|
||||
app.name=kenaito-conf-springboot3-client-demo
|
||||
app.version=1.0.0
|
||||
|
||||
# Kenaito Config Center
|
||||
kenaito.config.baseUrl=http://localhost:8080
|
||||
kenaito.config.appName=kenaito-springboot-demo
|
||||
kenaito.config.profile=daily
|
||||
kenaito.config.version=latest
|
||||
kenaito.config.token=
|
||||
kenaito.config.sync-interval-seconds=30
|
||||
|
||||
# Local configs (will be overridden by remote if exists)
|
||||
database.host=192.168.1.1
|
||||
database.port=8888
|
||||
database.name=xxxx
|
||||
database.user=xxxx
|
||||
database.password=xxxxxxxx
|
||||
Reference in New Issue
Block a user