"Could not resolve placeholder"解决方案
来源:互联网 发布:淘宝网什么时候成立的 编辑:程序博客网 时间:2024/05/21 09:39
除去properites文件路径错误、拼写错误外,出现"Could not resolve placeholder"很有可能是使用了多个PropertyPlaceholderConfigurer或者多个<context:property-placeholder>的原因。
比如我有一个dao.xml读取dbConnect.properties,还有一个dfs.xml读取dfsManager.properties,然后web.xml统一load这两个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" />
那么,一定会出"Could not resolve placeholder"。
一定要记住,不管是在一个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"
- />
注意两个都要加上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
P.S. 其实这个属性的名字我一直不理解……ignoreUnresolvablePlaceholders,忽略无法解析的占位符……那到底是怎样的占位符才是不可解析的?
- "Could not resolve placeholder"解决方案
- "Could not resolve placeholder"解决方案
- Could not resolve placeholder 解决方案
- Could not resolve placeholder"的解决方案
- Could not resolve placeholder
- Could not resolve placeholder
- Spring中报"Could not resolve placeholder"的解决方案
- Spring中报"Could not resolve placeholder"的解决方案
- Spring中报"Could not resolve placeholder"的解决方案
- spring报“Could not resolve placeholder”错误,解决方案
- spring报“Could not resolve placeholder”错误,解决方案
- Spring中报"Could not resolve placeholder"的解决方案
- Spring中报"Could not resolve placeholder"的解决方案
- Spring中报"Could not resolve placeholder"的解决方案
- Could not resolve placeholder 参考
- spring Could not resolve placeholder
- spring报“Could not resolve placeholder”错误
- Could not resolve placeholder 'jdbc.driverClass'
- 山寨腾讯“爱消除”游戏7日教程--DAY2
- java基础--集合
- Struts2——(3)ValueStack(值栈)
- html5 自学_First Day_2013.10.23
- 12本北美比较常用的机器学习/自然语言处理/语音处理经典书籍 .
- "Could not resolve placeholder"解决方案
- shell中的环境变量和自定义变量
- C语言字节对齐(以32位系统为例)
- Navicat 8 for MySQL的注册码
- 运行微信sdk demo工程时的问题
- readUTF()和read()方法的区别
- #define宏定义的陷阱
- vs2010创建和使用动态链接库(dll)
- visuall assist x 破解方法