您的位置:首页 > 编程语言 > Java开发

SpringBoot配置读取不到 PropertySourcesPlaceholderConfigurer和PropertyPlaceholderConfigurer

2018-01-11 21:04 531 查看
参考 :http://blog.csdn.net/yyhjava/article/details/53283515

PropertySourcesPlaceholderConfigurer和PropertyPlaceholderConfigurer冲突

SpringBoot 会注册一个 PropertySourcesPlaceholderConfigurer,

SpringBoot之前版本都是使用PropertyPlaceholderConfigurer,

所以对老项目升级的时候会出现有些配置读取不到,有些可以读取,很是诧异。

解决方案:如果系统使用springBoot,则继承PropertySourcesPlaceholderConfigurer,调用setProperties()方法把老的Properties设置进去,

然后系统只用一份PropertySourcesPlaceholderConfigurer.具体代码如下

@Configuration
public class ColumbusConfig extends PropertySourcesPlaceholderConfigurer implements InitializingBean {

@Override
public void afterPropertiesSet() throws Exception {
setProperties(loadOldConfig());
}
public static Properties loadOldConfig() {

return ......;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐