在开发中常常把配置信息放在properties文件中,然后spring的xml中引入。如果在多个spring的xml文件中引入properties
<context:property-placeholder ignore-unresolvable="true" location="classpath:config/wzk.properties" />spring启动会报错:
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definitionwith name Causedby: java.lang.IllegalArgumentException: Couldnot resolve placeholder即找不到某个配置项。
原来spring只允许有一个<context:property-placeholder/>
可以这样解决
<context:property-placeholder ignore-unresolvable="true" location="classpath:config/wzk.properties,classpath:config/mongodb.properties" />即在一个<context:property-placeholder/>中引入多个.properties文件,用英文逗号隔开。
本文介绍了解决Spring框架中多个XML文件重复加载同一配置文件的问题,通过在单个`context:property-placeholder`标签内指定多个配置文件路径来避免加载错误。
4万+

被折叠的 条评论
为什么被折叠?



