码迷,mamicode.com
首页 > 其他好文 > 详细

20140818bug

时间:2014-08-18 12:09:44      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   使用   io   文件   ar   2014   

多次使用Spring   placeholder   

报"Could not resolve placeholder"的解决方案

web.xml:

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
                WEB-INF/config/spring/dao.xml, 
                WEB-INF/config/spring/dfs.xml
        </param-value>
</context-param>

如果这两个xml文件中分别有:

<!-- dao.xml -->
<context:property-placeholder location="WEB-INF/config/db/dbConnect.properties" />

<!-- dfs.xml -->
<context:property-placeholder location="WEB-INF/config/dfs/dfsManager.properties" />

不管是在一个Spring文件还是在多个Spring文件被统一load的情况下,不允许直接写

<context:property-placeholder location="" />
<context:property-placeholder location="" /> 

解决方案:

  (1) 在Spring 3.0中,可以写:

<context:property-placeholder location="xxx.properties" ignore-unresolvable="true"/>
<context:property-placeholder location="yyy.properties" ignore-unresolvable="true"/>

   (2) 在Spring 2.5中,<context:property-placeholder>没有ignore-unresolvable属性,此时可以改用PropertyPlaceholderConfigurer。其实<context:property-placeholder location="xxx.properties" ignore-unresolvable="true" />与下面的配置是等价的

<bean id="随便" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
     <property name="location" value="xxx.properties" />
     <property name="ignoreUnresolvablePlaceholders" value="true" /> 
</bean>

正因为如此,写多个PropertyPlaceholderConfigurer不加ignoreUnresolvablePlaceholders属性也是一样会出"Could not resolve placeholder"。

 虽然两者是的等价的,但估计大家还是喜欢写<context:property-placeholder>多一些,毕竟简单一些嘛。所以如果是Spring 3.0,直接用解决方案(1)再简单不过了;

如果是Spring 2.5,需要费点力气改写成PropertyPlaceholderConfigurer

 

20140818bug,布布扣,bubuko.com

20140818bug

标签:style   blog   color   使用   io   文件   ar   2014   

原文地址:http://www.cnblogs.com/muzhongjiang/p/3918949.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!