4

Is there a way to set a property of a bean in a Spring configuration file to that of a string read from a Properties file?

e.g.

<bean id="...." class="....">
    <property name="loginURL">GET_THIS_VALUE_FROM_'ENV.PROPERTIES'_FILE</property>
</bean>

2 Answers 2

10

You should be able to use a PropertyPlaceHolderConfigurer to load a properties file, and then refer to the properties using an Spring-EL expression -

<context:property-placeholder location="classpath:custom.properties"/>

<bean id="...." class="....">
    <property name="loginURL">${propname}</property>
</bean>
Sign up to request clarification or add additional context in comments.

Comments

0

In my case, each server picked up its own property file whose name came from the system variable.

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations" value="classpath:/config/#{systemProperties['APPLICATION_PROPERTIES_FILE']}"/>
    </bean>  

After this, I had to add the property key via Spring JSTL expression e.g

class="org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter">
        <property name="signingKey" value="${oauth.signingkey}"/>
        <property name="jwtClaimsSetVerifier" ref="OauthClaimVerifier"/>
    </bean>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.