Search code examples
javaspringmavenconfiguration-filesapache-cocoon

Spring Could not resolve placeholder while loading config file form filesystem


I'm facing an issue with spring placeholder configuration. I've searched the web trying to find a solution but nothing worked for me at all.

We had used to use spring configurer for loading our .properties files and everything worked fine since the configfiles where located in META-INF dir.

Now we need to have our config files located in /etc/sep/properties directory or in some other filesystem directory.

I tried to use

<context:property-placeholder location="file:/etc/sep/properties/jdbc.properties" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.databaseurl}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <property name="initialSize" value="${jdbc.initialPoolSize}" />
    </bean>

the content of /etc/sep/properties/jdbc.properties is following:

cat /etc/sep/properties/jdbc.properties 
jdbc.driverClassName= org.postgresql.Driver
jdbc.dialect=org.hibernate.dialect.PostgreSQLDialect
jdbc.databaseurl=jdbc:postgresql://localhost:5432/sep?characterEncoding=utf8&autoReconnect=true
jdbc.username=****
jdbc.password=****

I also tried using another approach as folows, but it worked for me neither.

<context:property-placeholder properties-ref="prop" />

<util:properties id="prop" location="reso"/>

<bean id="reso" class="org.springframework.core.io.FileSystemResource">
    <constructor-arg index="0" value="/etc/sep/properties/jdbc.properties" />
</bean>

I don't know if it matters but we are using maven building, so that the application-context.xml is placed in core-lib.jar which is used in our web-app as dependency. Other config, such as logging work great.

I would be grateful for any suggestions.


Solution

  • Ok, I've finally resolved it. There were two things about it.

    At First: My tomcat server was not updating deployed files properly.

    And finally I'm not pretty sure if it helped, but we added one more slash after file: specification, so that the result was:

    <context:property-placeholder location="file:///etc/sep/properties/*.properties" />
    

    Now it is loading all config files properly.