fix(config): 统一配置键名并修复 EnvironmentInitializer 属性读取

- 统一使用 kenaito.config.baseUrl 替代 kenaito.config.base.url
- 更新示例配置参数(appName、profile、数据库配置键名)
- EnvironmentInitializer 添加从 Spring Environment 提取 kenaito.config.* 属性的逻辑
- .gitignore 添加 target 目录忽略规则
This commit is contained in:
2026-02-03 21:10:48 +08:00
parent 2549c76366
commit 6653c752e7
8 changed files with 62 additions and 30 deletions
@@ -116,7 +116,7 @@ public class ConfigcenterContext {
throw new IllegalArgumentException("[kenaito.config.profile] is required");
}
setApiBaseUrl(getProperty("kenaito.config.baseUrl", getProperty("kenaito.config.base.url", "")));
setApiBaseUrl(getProperty("kenaito.config.baseUrl", getProperty("kenaito.config.baseUrl", "")));
version = getProperty("kenaito.config.version", "latest");
ignoreGlobal = Boolean.parseBoolean(getProperty("kenaito.config.global-ignore", "false"));
@@ -145,7 +145,7 @@ public class ConfigcenterContext {
public void setApiBaseUrl(String apiBaseUrl) {
if (apiBaseUrl == null || apiBaseUrl.isBlank()) {
throw new IllegalArgumentException("[kenaito.config.base.url] is required");
throw new IllegalArgumentException("[kenaito.config.baseUrl] is required");
}
String[] urls = apiBaseUrl.split(",|;");
@@ -27,6 +27,19 @@ public class KenaitoEnvironmentInitializer implements EnvironmentPostProcessor {
if (ccContext.isRemoteEnabled() && !ccContext.isProcessed()) {
Properties properties = new Properties();
ccContext.setEnvironment((StandardEnvironment) environment);
// Extract kenaito.config.* properties from Spring Environment
environment.getPropertySources().forEach(ps -> {
if (ps instanceof org.springframework.core.env.EnumerablePropertySource) {
for (String key : ((org.springframework.core.env.EnumerablePropertySource<?>) ps).getPropertyNames()) {
if (key.startsWith("kenaito.config.") || key.equals("spring.application.name")) {
String val = environment.getProperty(key);
if (val != null) {
properties.setProperty(key, val);
}
}
}
}
});
ccContext.init(properties, true);
ccContext.mergeRemoteProperties(properties);
PropertiesPropertySource propertySource = new PropertiesPropertySource(ConfigcenterContext.MANAGER_PROPERTY_SOURCE, properties);