首页 > 其他 > 详细

Could not resolve placeholder'XXX' in string value "XXXX"

时间:2018-06-14 14:02:45      阅读:468      评论:0      收藏:0      [点我收藏+]

练习SSM项目的demo中遇到一个问题,我在applicationContext.xml中使用了<context:property-placeholder location="classpath:jdbc.properties"/>,我还想再引入另外一个resource.properties,resource.properties中的key我在controller层引用,用的是@Value(value="${type}")注解,总是出现如题的问题,从网上查了几个方案:

一、在同一个<context:property-placeholder/>标签中引入多个.properties标签

有些人表示,在spring容器中<context:property-placeholder/>标签只能存在一个,要引入多个.properties文件,可以通过这种方式:<context:property-placeholder  location="classpath:jdbc.properties,classpath:resource.properties"/> ,所以我在applicationContext.xml中的<context:property-placeholder/>标签引入后是没有再报错,但是不起作用,我在后台查看sql语句,占位符 ?并不是resource.properties中type所对应的值,而是直接将 ${type}作为值传到sql语句中,结果当然是查询不到数据。不知道是哪个地方出现了问题?还请高手指点一下,谢谢!

二、引入两个<context:property-placeholder/>标签,每一个标签引入一个.properties文件,而且必须同时加上ignore-unresolvable="true"

在applicationContext.xml文件中引入<context:property-placeholder location="classpath:jdbc.properties" ignore-unresolvable="true"/>,在springmvc.xml文件中引入<context:property-placeholder location="classpath:resource.properties" ignore-unresolvable="true"/>,这里有一个要点,就是spring的版本问题,好像2.5和之前的版本没有ignore-unresolvable=""这个参数,3.0以及自后才有,这样问题就解决了。

Could not resolve placeholder'XXX' in string value "XXXX"

原文:https://www.cnblogs.com/wsdwt/p/9182193.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!