spring boot 使用 EnvironmentAware 加载配置文件

@Configuration
public class PropertiesUtils implements EnvironmentAware {

	private int redisExpireTime;
	
	private boolean enabled;
	
	private int refreshTime;

	@Override
	public void setEnvironment(Environment environment) {
          //解析配置文件头 RelaxedPropertyResolver relaxedPropertyResolver = new RelaxedPropertyResolver(environment, "custom."); this.redisExpireTime=Integer.valueOf(relaxedPropertyResolver.getProperty("redisExpireTime")); this.enabled=Boolean.valueOf(relaxedPropertyResolver.getProperty("enabled")); this.refreshTime=Integer.valueOf(relaxedPropertyResolver.getProperty("refreshTime")); }

  

posted on 2018-07-17 16:58  知了不了了之  阅读(2555)  评论(0编辑  收藏  举报