feat(springboot3): 添加 RefreshScope 自动配置支持
- 新增 KenaitoRefreshAutoConfiguration 类,实现 ApplicationContextAware - 更新 spring.factories,注册 EnableAutoConfiguration - 与 Spring Boot 2 客户端保持一致,支持 @Value 和 @ConfigurationProperties 动态刷新
This commit is contained in:
@@ -36,7 +36,7 @@
|
||||
<dependency>
|
||||
<groupId>cn.odboy</groupId>
|
||||
<artifactId>kenaito-conf-springboot2-client</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.0.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
+15
@@ -1,5 +1,6 @@
|
||||
package cn.odboy.demo;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -25,6 +26,9 @@ public class ConfigController {
|
||||
@Value("${database.password:unknown}")
|
||||
private String password;
|
||||
|
||||
@Autowired
|
||||
private DatabaseProperties databaseProperties;
|
||||
|
||||
@GetMapping("/")
|
||||
public Map<String, Object> index() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
@@ -36,6 +40,17 @@ public class ConfigController {
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/configprops")
|
||||
public Map<String, Object> configprops() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("host", databaseProperties.getHost());
|
||||
result.put("port", databaseProperties.getPort());
|
||||
result.put("name", databaseProperties.getName());
|
||||
result.put("user", databaseProperties.getUser());
|
||||
result.put("password", databaseProperties.getPassword());
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/health")
|
||||
public String health() {
|
||||
return "OK";
|
||||
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package cn.odboy.demo;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Database configuration properties
|
||||
*
|
||||
* @author odboy
|
||||
* @version 2.0.0
|
||||
* @date 2026-10-16
|
||||
*/
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "database")
|
||||
public class DatabaseProperties {
|
||||
|
||||
private String host;
|
||||
private String port;
|
||||
private String name;
|
||||
private String user;
|
||||
private String password;
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public String getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(String port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ kenaito.config.appName=kenaito-springboot-demo
|
||||
kenaito.config.profile=daily
|
||||
kenaito.config.version=latest
|
||||
kenaito.config.token=
|
||||
kenaito.config.sync-interval-seconds=30
|
||||
kenaito.config.sync-interval-seconds=10
|
||||
|
||||
# Local configs (will be overridden by remote if exists)
|
||||
database.host=192.168.1.1
|
||||
|
||||
Reference in New Issue
Block a user