0

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

  • Look at this thread : http://stackoverflow.com/questions/3965446/how-to-read-system-environment-variable-in-spring-applicationcontext – Thomas Nov 06 '13 at 17:06

2 Answers2

1

Just enclose the property in ${}:

<ctx:property-placeholder location="file:${MY_ENV}/yourfile.properties"/>
Chris
  • 22,923
  • 4
  • 56
  • 50
0

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.

MattSenter
  • 3,060
  • 18
  • 18