1
votes

I am loading property file in spring-context.xml and i am giving external property file location in ${spring.profiles.active}.properties which is in classpath and using the location as a placholder in spring-context.xml. My spring-context.xml is:

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="ignoreResourceNotFound" value="true" />
    <property name="ignoreUnresolvablePlaceholders" value="true" />
    <property name="searchSystemEnvironment" value="true" />
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
    <property name="locations" ref="propertyConfigurerFiles" />
    </bean>
    <bean id="propertyConfigurerFiles" class="java.util.ArrayList">
    <constructor-arg>
    <list>
    <value>/WEB-INF/properties/common.properties</value>

    <!--In Developemnet Enviroenment it will be dev.properties-->
    <value>/WEB-INF/properties/${spring.profiles.active}.properties</value> 

    <!--External Property File Location as a Placeholder-->
    <value>${app.config.batch.location}</value>

    </list>
    </constructor-arg>
    </bean>

And my dev.properties is:

    app.config.batch.location=E:/project/properties/config.properties

My problem is that is ${app.config.batch.location} placeholder is not resolved in spring-context.xml and its trying to load file ${app.config.batch.location} in place of E:/project/properties/config.properties.

I hope I explained the problem well. Please help!

Thanks in Advance!!!

2

2 Answers

0
votes

You need to create bean of class PropertyPlaceHolderConfigurer. Not just some ArrayList bean. Why do you think you need this ArrayList bean?

0
votes

It seems you are using spring profiles, instead of messing with initialization time property value binding what you can do is ... 1) read the property file(profile's) /WEB-INF/properties/${spring.profiles.active}.properties 2) create a java class that can read these property values. (don't forget to use spring profiles interfacing class) 3) as you are trying to read a property file whose location is embedded in property file(step-1), object created at step-2 will give value for key <value>${app.config.batch.location}</value> now you can load this property file using available file reader class. 4) create Properties object and access the values in it.

Note:: if any of your bean initialization depends on key-value read at step-4, do initialization manually or create your ***custom class(servlet) that get loaded before any other class (even spring's DispactherServlet).