1

Before I start, I have already read this and this, and still could not figure out the issue.

I have a Spring application (you'll realise soon that my Spring knowledge is not very extensive) and four different environments (test, production...). Before, my properties file used in the PropertyPlaceholderConfigurer was identical for all of them. But now I want to change it so every environment has slightly different properties. To do so, I have added an environment variable to the value so it grabs the right properties file in servlet.xml.

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations">
     <list>
        <value>classpath:circuitbreaker.properties</value>
        <value>classpath:${environment}.trackinganonymisation.properties</value>
        <value>classpath:runtime.properties</value>
     </list>
  </property>
</bean>

My question is: where do I set the environment variable so I get it to be populated with the environment value?

Community
  • 1
  • 1
Tavo
  • 3,087
  • 5
  • 29
  • 44
  • 2
    Did you consider using [profiles](http://www.baeldung.com/spring-profiles)? – Ernest Sadykov May 13 '15 at 14:04
  • As a system property or environment property other values aren't going to be resolved at this point. – M. Deinum May 13 '15 at 14:21
  • @Xokker profiles sound like a good alternative. It might be a solution, but I am not sure it's what I was looking for. It might be worth a try for the lack of a better solution. – Tavo May 13 '15 at 15:13
  • @Tavo how do you want to set the `environment`? Why system property is not suitable for you? – Ernest Sadykov May 13 '15 at 15:21
  • @Xokker I need to set the environment via xml configuration. I have another project that does it programmatically using `@Autowired static Environment env;` and then `propertySourcesPlaceholderConfigurer.setEnvironment(environment)` Not sure how that relates though. – Tavo May 13 '15 at 15:32

1 Answers1

0

Turns out that the solution was already in place and I didn't know. ${environment} was set as a system property in the production machine to which I had no access. Even so, the solution was just to add that property to my local development environment.

Tavo
  • 3,087
  • 5
  • 29
  • 44