基于spring的PropertySource类实现配置的动态替换


public class ConfigPropertySource extends PropertySource<Properties> implements PriorityOrdered, BeanFactoryPostProcessor, EnvironmentAware{

public void init() {
this.loadConfig();
this.env.getPropertySources().addFirst(this);
}

private Properties parseConfig(String config) {
Properties properties = new Properties();
if(StringUtils.isNotEmpty(config)) {
try {
properties.load(new StringReader(config));
} catch (Exception var4) {
throw new IllegalArgumentException("detail center parse config error, config:" + config, var4);
}
}

return properties;
}

public Object getProperty(String name) {
return this.source.get(name);
}

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM