Reputation: 31
Hello I am new to Spring so please forgive me if its a silly question.
I need to load a properties file from a path specified in the environment variables, For example, my environment variable will contain a pah to a folder - MY_ENV=D:\abc. And in this directory i will have my .properties file.
Thanks
Upvotes: 0
Views: 1707
Reputation: 3120
You can use SpEL to load environment variables into your configs:
<bean id="someBean" class="com.mypackage.SomeClass">
<property name="somePropertiesPath" value="#{environment['MY_ENV']}/my.properties" />
</bean>
I don't know if you were looking to use your properties as a PropertyPlaceholderConfigurer
or just as another Properties
bean, so if you clarify that point, I can give you the exact xml you need.
Upvotes: 0
Reputation: 23171
Just enclose the property in ${}:
<ctx:property-placeholder location="file:${MY_ENV}/yourfile.properties"/>
Upvotes: 1