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

练习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以及自后才有,这样问题就解决了。

posted @ 2018-06-14 11:25  神罗天征  阅读(616)  评论(0编辑  收藏  举报