1. 程式人生 > >Could not resolve placeholder'XXX' in string value "XXXX"

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

同時 占位符 bsp 通過 存在 遇到 could oca nor

練習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"