Spring context:property-placeholder can't resovle nested variables -
i have 2 projects -- project-web, , project-service, both of them utilize spring core 3.1.3 , have configurations load properties corresponding property files:
project-web -- spring integration based project, in spring config file:
<context:property-placeholder location="web-inf/spring-integration/spring-integration.properties" ignore-resource-not-found="true" /> <import resource="classpath*:meta-inf/spring/applicationcontext.xml" />
where import include spring configuration file project-service, , in project-service project, have next configured:
<context:property-placeholder location="classpath:meta-inf/application.properties, classpath:meta-inf/db.properties" ignore-resource-not-found="true"/> <import resource="classpath:meta-inf/spring/applicationcontext-data.xml"/>
where import include spring configuration daos, within applicationcontext-data.xml have:
<bean id="datasource" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close"> <property name="driverclassname" value="${db.${db.type}.driver}" /> <property name="url" value="${db.${db.type}.url}"/> <property name="username" value="${db.${db.type}.username}" /> <property name="password" value="${db.${db.type}.password}" /> </bean>
when run unit tests project-service, fine, variables resolved correctly without problem. when run project-web (project-service included .jar file in web-inf/lib folder of project-web), throws error during start saying can't resolve ${db.type}:
org.springframework.beans.factory.beandefinitionstoreexception: invalid bean definition name 'datasource' defined in class path resource [meta-inf/spring/applicationcontext-data.xml]: not resolve placeholder 'db.type' in string value "db.${db.type}.driver" @ org.springframework.beans.factory.config.placeholderconfigurersupport.doprocessproperties(placeholderconfigurersupport.java:209) ~[spring-beans-3.1.3.release.jar:3.1.3.release] @ org.springframework.context.support.propertysourcesplaceholderconfigurer.processproperties(propertysourcesplaceholderconfigurer.java:174) ~[spring-context-3.1.3.release.jar:3.1.3.release] @ org.springframework.context.support.propertysourcesplaceholderconfigurer.postprocessbeanfactory(propertysourcesplaceholderconfigurer.java:151) ~[spring-context-3.1.3.release.jar:3.1.3.release] ......................
note: can't declare in project-web, because project-service used other projects. know why in project-service works when runs lone not when included project-web? can't resolve nested variable ${db.type}
the problem first propertyplaceholderconfigurer
trying resolve placeholder needs resolved sec one.
you can either utilize different prefix each 1 (e.g. !{
instead of ${
1 of them), or set
ignore-unresolvable="true"
on first 1 - leave resolution other one.
spring spring-integration
No comments:
Post a Comment