user1235366
user1235366

Reputation: 1

Properties not being substituted in applicationContext.xml

I'm facing a very weird issue. I'm tring to configure the properties of my datasource declared in my spring applicationcontext.xml file via a PropertyPlaceholderConfigurer class. The application context file looks like this:-

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:ws="http://jax-ws.dev.java.net/spring/core" xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
xmlns:jms="http://www.springframework.org/schema/jms"
xsi:schemaLocation="http://jax-ws.dev.java.net/spring/servlet http://jax-ws.dev.java.net/spring/servlet.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://jax-ws.dev.java.net/spring/core http://jax-ws.dev.java.net/spring/core.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.4.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<!--  Spring configurations used by LCM Impl classes -->
<bean id="lcmPropertyConfigurer"
       class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:/activemq.properties</value>
            <value>classpath:/jdbc.properties</value>
        </list>
    </property>
</bean>


<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy- method="close">
<property name="driverClassName" value="${db.driverClassName}" />
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
</bean>

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="dataSource"/>
</bean>
</beans>

I have tried using the context:property-placeholder tag as well but it doesn't seem to have any effect. The above mentioned properties files are deployed successfully under the WEB-INF/classes directory as well.

For some reason, the spring container is able to load the properties files(checked with an invalide properties file and it throws a FNF exception) but not able to substitute the property placeholders with their values.

I'm using a tomcat 7 WS with the CATALINA.BASE pointing to my runtime. Has anybody faced this issue before? Any solutions?

Upvotes: 0

Views: 2014

Answers (2)

cyotee doge
cyotee doge

Reputation: 1138

Try the following configuration.

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:activemq.properties</value>
            <value>classpath:jdbc.properties</value>
        </list>
    </property>
</bean>

The issue is likely the fact that you even named the PropertyPlaceholderConfigurer bean. Most Spring internal beans are not given an id, as the framework is configured to look for certain bean names, and often the default bean name is the auto-generated name based on the object type.

Upvotes: 0

duffymo
duffymo

Reputation: 308763

Take that leading slash out of the values:

        <value>classpath:activemq.properties</value>
        <value>classpath:jdbc.properties</value>

Upvotes: 1

Related Questions