0

IT changed some server url, and I want to setup the application with the new settings.

That server url variable is defined in the application.properties file available in classpath, but the new value is defined in the external application.properties file.

However for some reason the application still uses the server url defined in the classpath application properties file, ignoring the new value in the external file. The override is not working!

If I understand well the documentation it should work.

In main spring boot class I have defined two properties file with @PropertySources annotation.

@SpringBootApplication
@PropertySources({
    @PropertySource("classpath:application.properties"),
    @PropertySource("file:${SCDWPPT_HOME}/application.properties")
})
public class ScdwpptApplication extends SpringBootServletInitializer {
...
}
pillesoft
  • 486
  • 1
  • 6
  • 20
  • 3
    Because you are working against Spring Boot. Remove the property sources and let Spring Boot do the loading. So yes it will work but as you defined `@PropertySource`which takes precedence again. – M. Deinum Jul 12 '23 at 13:28
  • What you say is strange to me. The fact is that if there is a setting defined only in the external file, it works. But if the same setting is defined in both files, the override doesn't work. Considering your proposal, I can understand that the application.properties in the classpath is automatically loaded, but how to "tell" to spring boot the external properties file? with --spring.config.location environment setting? – pillesoft Jul 12 '23 at 13:41
  • I think I answered the same question extensivly [here](https://stackoverflow.com/a/76231245/2696260) and what you can use. – M. Deinum Jul 12 '23 at 13:48
  • Thanks @deinum.biz! Finally I deleted @PropertySources from application class, and setup profile based configuration files, plus I defined an optional one with spring.config.import – pillesoft Jul 13 '23 at 15:56

0 Answers0