問候,Spring:爲什麼不能以分隔的.xml配置兩個ServletContextPropertyPlaceholderConfigurer?
我正在研究基於彈簧的Web應用程序。情況是:
- 有兩個.xml文件,一個應用程序的context.xml,另一種是默認的context.xml
- 應用程序的context.xml將負載Web上下文當Tomcat啓動,其配置在web.xml
應用程序的context.xml ServletContextPropertyPlaceholderConfigurer加載一些properties.and進口默認的context.xml
,因爲默認的context.xml是在另一個項目,我希望它有它自己的。特性(缺省context.propertie s)文件並設置一個ServletContextPropertyPlaceholderConfigurer來加載屬性。
當前結果是:在default-context.properties屬性未加載,並且在默認的context.xml的ServletContextPropertyPlaceholderConfigurer不inited。據報道
無法解決佔位符XXXXXX」
我嘗試了一些組合,
1.to在應用程序的context.xml的ServletContextPropertyPlaceholderConfigurer負荷default-context.properties,它的工作。
2.to application-context.xml中加載default-context.properties的PropertyPlaceholderConfigurer,不工作。我猜是因爲Pro pertyPlaceholderConfigurer無法加載到servlet上下文?
3.在default-context.xml中雙向加載default-context.properties(ServletContextPropertyPlaceholderConfigurer或PropertyPlaceholderConfigurer) 無效。
我不明白爲什麼只有一個ServletContextPropertyPlaceholderConfigurer可以在servlet上下文中配置?
配置是這樣的:在應用程序的context.xml
<class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:etc/system.properties
</value>
...
在默認的context.xml:
<bean id="tempName123"
class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer" >
<property name="locations">
<list>
<value>classpath:etc/default-datasource.properties</value>
</list>
</property>
</bean>
Ritesh,謝謝你的回覆。我試過這種方法,沒有工作。第二個ServletContextPropertyPlaceholderConfigurer bean不是init,也不是上下文加載的。 – Yang 2010-12-06 01:58:51