Spring 3.1 环境不适用于用户属性文件
我正在这样做..
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);
有谁知道为什么我的属性没有加载到环境中?谢谢。