Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using spring 3.1 with spring profiles to load the beans. In my app context file, I load the properties like :

<context:property-placeholder order="1"  location="classpath*:META-INF/spring/*_${spring.profiles.active}.properties" ignore-unresolvable="true"/>

And then I use the property value to load the data source bean like

<property name="driverClassName" value="${database.driverClassName}"/>

It works fine. The problem starts when I add a couple of more property placeholders so that properties from some database tables can be loaded.

This uses a properties reference loaded by

<bean id="configFactoryBean"
class="org.springmodules.commons.configuration.CommonsConfigurationFactoryBean">
   <constructor-arg ref="globalSystemConfiguration"/>
</bean>

To add to the details, this configFactoryBean uses the datasource to load the properties from the database.

When I do this, I have the following exception:

java.lang.ClassNotFoundException: ${database.driverClassName}

My analysis is that its trying to load the datasource before resolving the property from the first context property placeholder. I may be wrong. Or maybe spring profile variable is not resolved properly.

Can anyone please help me to fix this.

Thanks Akki

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
282 views
Welcome To Ask or Share your Answers For Others

1 Answer

This bug about multiple property placeholders might relate to your problem: https://jira.spring.io/browse/SPR-9989

When using multiple PropertyPlaceholderConfigurer in conjunction with @Value annotation and default value for placeholders syntax (ie ${key:defaultValue}), only the first PropertyPlaceholderConfigurer is used. If this configurer does not contain the desired value, it falls back to @Value default even if the second PropertyPlaceholderConfigurer contains the value.

Affects Version/s: 3.1.3


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...