The Science Boy
The Science Boy

Reputation: 359

How do I add external property file location to Spring Boot application deployed to tomcat 6?

I have a Spring Boot application that I configure with annotations. I have application.properties and application-{profile}.properties files already with data in them. Problem is I now want to define a WAR-external location on the Tomcat 6 server where I can put configuration files that take precedence. That is, any settings I put in those properties files should trump any values in application.properties or application-{profile}.properties.

How can I accomplish this in the easiest possible way?

I have already tried to add @PropertySources but that has a lower priority in the properties files order so that is not a possible solution. Can I change the property file loading order easily?

It is not possible to add environment variables to the server, since that might affect other deployed applications. The WAR must be self-contained and deliver everything it needs (except this external properties override file).

Upvotes: 0

Views: 2530

Answers (1)

Stephane Nicoll
Stephane Nicoll

Reputation: 33091

You could configure spring.config.location as described in the doc or you could implement an EnvironmentPostProcessor if you want this to apply regardless.

There is a sample in this university session at Devoxx where we showcase how to read a file from the home directory and add it after command line properties. You could do pretty much the same thing and order them the way you want.

The sample app is available here if you want to give that a try.

Upvotes: 1

Related Questions