【发布时间】:2013-01-05 07:52:15
【问题描述】:
我正在这样做..
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context);
xmlReader
.loadBeanDefinitions(new ClassPathResource("SpringConfig.xml"));
PropertySourcesPlaceholderConfigurer propertyHolder = new PropertySourcesPlaceholderConfigurer();
propertyHolder.setLocation(new ClassPathResource(
"SpringConfig.properties"));
context.addBeanFactoryPostProcessor(propertyHolder);
......
context.refresh();
现在在我的@Configuration 文件中,如果我这样做,我的 SpringConfig.properties 中的属性不会被拾取...
@Autowired
private Environment env
.....
env.getProperty("my.property")
但是如果我使用,我会得到那个属性
@Value("${my.property}")
private String myProperty;
我什至尝试像这样添加更多行,但没有用。
ConfigurableEnvironment env = new StandardEnvironment();
propertyHolder.setEnvironment(env);
有人知道为什么我的属性没有加载到环境中吗?谢谢。
【问题讨论】: