spring只允许有一个<context:property-placeholder/>,如果想加载多个文件,就会报错,后加载的文件无法加载成功,解决方法如下,有三个,任选其一即可:
1.分不同的XML文件来加载不同的properties文件
如,applicationContext-dao.xml加载jdbc.properties,
applicationContext-redis.xml加载redis.properties
2.以逗号隔开不同的文件
如,<context:property-placeholder location="classpath:jdbc.properties,classpath:redis.properties"/>
3.用util标签
现在头文件引入:
xmlns:util="http://www.springframework.org/schema/util"
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
然后:
<util:properties id="xxx" location="classpath:conf.properties"/>
代码中:
@Value("#{xxx['MQ']}") private String MQ;
注:MQ为conf.properties中key