我正在编写代码,以便能够从文件中热重新加载属性。我从已挂载的卷中提取kubernetes密钥作为类中的基础(KubernetesConfigurationClient)。
现在我有一个这样的类:
@Singleton
@Requires(property = ConfigurationClient.ENABLED, value = StringUtils.TRUE, defaultValue = StringUtils.FALSE)
@BootstrapContextCompatible
public class MountedVolumeConfigurationClient implements ConfigurationClient {另一个是:
@ConfigurationProperties(MountedVolumeConfiguration.PREFIX)
@BootstrapContextCompatible
public class MountedVolumeConfiguration {我的application.yml:
micronaut:
application:
name: micronaut-service
server:
port: 8080我的bootstrap.yml
micronaut:
application:
name: micronaut-service
config-client:
enabled: true
poc:
client:
mounted-volumes:
enabled: true
config-map-paths:
- /configmaps
secret-paths:
- /secrets现在,如果我的gradle.build依赖项中有implementation("io.micronaut.kubernetes:micronaut-kubernetes-discovery-client:2.2.1-SNAPSHOT"),代码就可以很好地工作,但是如果没有,它就不会加载Singleton bean。
我发现原因在于DefaultApplicationContext类中的这段代码
private BootstrapPropertySourceLocator resolveBootstrapPropertySourceLocator(String... environmentNames) {
if (this.bootstrapPropertySourceLocator == null) {
BootstrapApplicationContext bootstrapContext = new BootstrapApplicationContext(bootstrapEnvironment, environmentNames);
bootstrapContext.start();
if (bootstrapContext.containsBean(BootstrapPropertySourceLocator.class)) {
initializeTypeConverters(bootstrapContext);
bootstrapPropertySourceLocator = bootstrapContext.getBean(BootstrapPropertySourceLocator.class);
} else {
bootstrapPropertySourceLocator = BootstrapPropertySourceLocator.EMPTY_LOCATOR;
}
}
return this.bootstrapPropertySourceLocator;
}当我的依赖中有micronaut-kubernetes-discovery-client时,if (bootstrapContext.containsBean(BootstrapPropertySourceLocator.class))是真的,当我没有的时候是假的。
添加了一些上下文,我正在尝试在kubernetes中将secrets和configmaps作为卷安装时都可以热重新加载。现在,micronaut仅监视configmap的更改,并且只能从已安装的卷中读取机密。我希望完全独立于kubernetes API。
发布于 2021-02-04 18:42:38
我刚刚发现我遗漏了这个依赖项:当应用io.micronaut.kubernetes:micronaut-kubernetes-discovery-client:2.2.1-SNAPSHOT时,它也包含这个依赖项:io.micronaut:micronaut-discovery-client。
https://stackoverflow.com/questions/66037424
复制相似问题