rak*_*sja 12 java configuration spring properties spring-mvc
让这个类覆盖另一个Config类中已经设置的@PropertySource.
@Configuration
@PropertySource({ "classpath:${env.placeholder}/app.properties" })
public class PropertyOverrideConfig {
}
Run Code Online (Sandbox Code Playgroud)
但是每当缺少文件或占位符时,它都会导致上下文加载失败.我需要将以下标志设置为该注释加载属性,以便它将跳过,如果它无法找到该属性.
setIgnoreResourceNotFound(true);
setIgnoreUnresolvablePlaceholders(true);
Run Code Online (Sandbox Code Playgroud)
问题1:为@PropertySource设置这些标志的适当方法是什么?
更新: 尝试将@Bean添加到同一个类而没有引用此页面的注释,它也不会选择属性文件.我没有xml配置.
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
final PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
Resource[] resources = new ClassPathResource[ ] {
new ClassPathResource( "classpath:${env.placeholder}/app.properties" ) };
pspc.setLocations( resources );
pspc.setIgnoreResourceNotFound(true);
pspc.setIgnoreUnresolvablePlaceholders(true);
return pspc;
}
Run Code Online (Sandbox Code Playgroud)
问题2:我确信我错过了一些东西,但无法弄清楚它是什么,任何帮助都会很棒.
| 归档时间: |
|
| 查看次数: |
5637 次 |
| 最近记录: |