0

In my Spring project I am using a dependency project developed in Spring. This dependency has its own properties file and have defined a property which points to localhost. Now in my setup, I want this property to be pointing to another URL but not localhost. I am trying to override this in my properties file using addFirst method of property sources, but the dependency still loads the original property value.

ConfigurableEnvironment environment = applicationContext.getEnvironment();
//here i overload the props
environment.getPropertySources().addFirst(
                new ResourcePropertySource("classpath:conf/app.properties")); 
LOG.debug("dependency property: " + applicationContext.getEnvironment().
getProperty("server.hostname")); // here it prints the overloaded value in app.properties

When I print the overloaded property I get the overloaded property value, but when the program gets executed it points to localhost. Is this the way to override dependent properties ? Spring version is 3.2

Dhanush Gopinath
  • 5,652
  • 6
  • 37
  • 68

1 Answers1

0

The point is, that in the ProperySources the last one wins.

(Its like in a Database, the last one that writes wins).

Try to use simply add.

Ralph
  • 118,862
  • 56
  • 287
  • 383