今天想使用spring里面的@Value的注解
参考了几个网络上的配置,但是始终不生效,不知道自己是什么地方配错了。
最后使用了以下方式。
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>file:conf.properties</value>
<value>file:conf1.properties</value>
</list>
</property>
</bean>
然后在java文件中
@Value("#{configProperties['value']}")
需要注意的是,如果读取两个配置文件,conf.properties, conf1.properties 第二个配置文件的值会覆盖第一个。
还有一个值得注意的,在xml中如果有value里面有双引号的。可以使用转移符" 而不是\"