1. 程式人生 > >解決關於配置文件的占位符無法讀取問題

解決關於配置文件的占位符無法讀取問題

文件中 問題 反射 esp 解決方法 strong 解決 class config

前提是:

  其他的配置文件中已經配置了<context:property-placeholder location="classpath:jdbc.properties"/>

主要原因是:

  Spring容器采用反射掃描的發現機制,在探測到Spring容器中有一個org.springframework.beans.factory.config.PropertyPlaceholderConfigurer的Bean就會停止對剩余PropertyPlaceholderConfigurer的掃描(Spring 3.1已經使用PropertySourcesPlaceholderConfigurer替代PropertyPlaceholderConfigurer了)。而<context:property-placeholder/>這個基於命名空間的配置,其實內部就是創建一個PropertyPlaceholderConfigurer Bean而已。換句話說,即Spring容器僅允許最多定義一個PropertyPlaceholderConfigurer(或<context:property-placeholder/>),其余的會被Spring忽略掉。

解決方法是:   改成<context:property-placeholder location="classpath:redis.properties" ignore-unresolvable="true"/>

解決關於配置文件的占位符無法讀取問題