自动装配发生的时间比
load()所谓的晚(由于某种原因)。
一种解决方法是实现
EnvironmentAware并依赖Spring调用
setEnvironment()方法:
@Configuration@ComponentScan(basePackages = "my.pack.offer.*")@PropertySource("classpath:OfferService.properties")public class PropertiesUtil implements EnvironmentAware { private Environment environment; @Override public void setEnvironment(final Environment environment) { this.environment = environment; } @Bean public String load(String propertyName) { return environment.getRequiredProperty(propertyName); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)