Spring :Why can't configure two ServletContextPropertyPlaceholderConfigurer in separated .xml? -
greetings,
i working on spring based web application. situation :
- there 2 .xml file 1 application-context.xml , other default-context.xml
- application-context.xml load web context when tomcat started ,which configured in web.xml
application-context.xml servletcontextpropertyplaceholderconfigurer loaded properties.and import default-context.xml
because default-context.xml in project, , want have own .properties(default-context.properties) file , set servletcontextpropertyplaceholderconfigurer load properties.
the current result : properties in default-context.properties not loaded, , servletcontextpropertyplaceholderconfigurer in default-context.xml not inited. reports
can't resolve placeholder xxxxxx"
i tried combinations,
1.to load default-context.properties in application-context.xml 's servletcontextpropertyplaceholderconfigurer ,its worked.
2.to load default-context.properties in application-context.xml 's propertyplaceholderconfigurer ,not work. guess because propertyplaceholderconfigurer can't load servlet context?
3.loading default-context.properties in default-context.xml in both ways (servletcontextpropertyplaceholderconfigurer or propertyplaceholderconfigurer) not work.
i can't figure out why there's 1 servletcontextpropertyplaceholderconfigurer can configured in servlet context?
configuration : in application-context.xml
<class="org.springframework.web.context.support.servletcontextpropertyplaceholderconfigurer"> <property name="locations"> <list> <value>classpath:etc/system.properties </value>
...
in default-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>
you can use different placeholder prefix , suffix second bean. following declaration can use placeholder #[some.property.name].
<bean class="org.springframework.web.context.support.servletcontextpropertyplaceholderconfigurer" p:location="classpath:etc/default-datasource.properties" p:placeholderprefix="#[" p:placeholdersuffix="]"> </bean>
Comments
Post a Comment