如何解决Micronaut:BootstrapContext 不包含 BootstrapPropertySourceLocator bean
我正在编写能够从文件热重载属性的代码。我从已安装的卷中获取 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;
}
if (bootstrapContext.containsBean(BootstrapPropertySourceLocator.class))
当我的依赖项中有 micronaut-kubernetes-discovery-client 时为真,而当我没有时为假。
一些添加的上下文,我试图能够在将机密和配置映射作为卷安装在 kubernetes 中时热重新加载它们。现在 micronaut 只监视 configmap 更改,并且只能从已安装的卷中读取机密。我想完全独立于 kubernetes API。
解决方法
刚刚发现我缺少这个依赖项:io.micronaut:micronaut-discovery-client
在应用 io.micronaut.kubernetes:micronaut-kubernetes-discovery-client:2.2.1-SNAPSHOT
时它也包含那个。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。