java - @ConfigurationProperties 在以编程方式添加活动配置文件后重新加载
问题描述
我有一个用@ConfigurationProperties 注释的类。
@ConfigurationProperties
@Configuration
@DependsOn("AddDefaultProfile")
public class MyProperties(){
....
}
我有几个配置文件chrome, safari, ie, and en_US, fr_CA
等。我的运行参数看起来像-Dspring.profiles.active=chrome, en_US
.
现在我想检查是否指定了语言,如果没有,我使用environment.addActiveProfile("en_US")
. 问题是我的 MyProperties 没有重新加载。通过调试,我可以看到环境在活动配置文件中有 en_US,但 propertySource 仍然有旧的配置文件。
如何使用我的新配置文件重新加载 MyProperties。
解决方案
您可以尝试调用此方法WebApplicationContextUtils#initServletPropertySources(org.springframework.core.env.MutablePropertySources, javax.servlet.ServletContext, javax.servlet.ServletConfig)
,但我不确定这是否有用
推荐阅读
- mule - XML 到 JSON 数据映射 - xml 的子类(子类)未显示为与 mule dataweave 中的 JSON 映射
- neural-network - 如何将 2 个 sklearn 模型保存在一个文件中
- powerbi - 无法使用 restapi 连接到 Power bi?
- postgresql - PostgreSQL:光栅到矢量的转换
- scala - 如何在 Scala 中弃用外部库?
- javascript - 如何使用 Typescript 在 Cypress 中向 .contains 添加超时?
- go-ethereum - bootnode -writeaddress 命令的输出长度是 64 字节,而不是预期的 128 字节,为什么?
- validation - Flutter:如何避免验证器中的特殊字符
- android - 获取孩子firebase android的数量并将所有孩子放在String arrayList中
- symfony - symfony phpunit 令牌存储