Looking for a ${property}

“Location, Location, Location” may not be enough.

Having property files loaded using ProperyPlaceholderConfigurer bean or the modern <context:property-placeholder> can become a real pain when the placeholders are distributed among the jars.

<context:property-placeholder location=”classpath*:*.properties”/>

Well, only location can be set here, the rest is default. Pretty cool, but it is not doing it… We look back to the old fashion bean

<bean class=”org.springframework.beans.factory.config.PropertyPlaceholderConfigurer”>
<property name=”locations” value=”classpath:*.properties”/>
</bean>

The hack comes here: change from the default placeholderPrefix to a specific one, unique among jars used and everything is gonna be alright.

<property name=”placeholderPrefix” value=”£{“/>

Don’t forget now to change the references to the properties (from ${…} to £{…}).

Source 1 Source 2

<bean id=”clientPropertyConfigurer” class=”org.springframework.beans.factory.config.PropertyPlaceholderConfigurer”>
<property name=”searchSystemEnvironment” value=”true”/>
<property name=”systemPropertiesMode” value=”2″/>
<property name=”order” value=”100″/>
<property name=”properties”>
<props>
<prop key=”BPB_SERVICES_HOST”>bpb-services01</prop>
<prop key=”BPB_SERVICES_HOST_PORT”>1099</prop>
</props>
</property>
<property name=”placeholderPrefix” value=”#{“/>
</bean>
This entry was posted in Cornel's Blog, Java & JEE and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>