web項目啓動時,出現“Could not resolve placeholder 'redis.pool.maxTotal' in string value "${redis.pool.maxTotal}”,
除去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",一個加另一個不加也是不行的
整合Redis時,出現這種情況->