【发布时间】:2018-05-29 21:41:39
【问题描述】:
由于组织限制,我仅限于作为 WAR 文件部署到 Tomcat 服务器,我们使用标准做法 {applicationName}.properties 捆绑在 WAR 中,然后 Tomcat 服务器有一个 {applicationName}-override.properties类路径。
我有以下 bean 定义来加载属性。
@Bean
public PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer();
Resource[] resources = new Resource[2];
resources[0] = new ClassPathResource("parameter-portal.properties");
resources[1] = new ClassPathResource("parameter-portal-override.properties");
propertyPlaceholderConfigurer.setLocations(resources);
propertyPlaceholderConfigurer.setIgnoreResourceNotFound(true);
propertyPlaceholderConfigurer.setIgnoreUnresolvablePlaceholders(true);
return propertyPlaceholderConfigurer;
}
问题是当我将 Environment 注入另一个 bean 时,我的所有属性都不存在。
如下调用失败:
environment.getRequiredProperty("application.security.ldap.userSearchBase"
PropertyPlaceholderConfigurer 中的属性不应该在 Environment 中可用吗?
如果我执行以下操作,它确实有效,但我希望这些属性在环境中可用
@Value("${application.security.ldap.userSearchBase}")
private String userSearchBase;
注意:如果我使用 PropertySourcesPlaceholderConfigurer,也会发生同样的事情。
【问题讨论】:
标签: java spring spring-boot