Daniel Fernández
Daniel Fernández

Reputation: 7465

Spring Boot: Exclude configuration properties for profiles from jar package

I have a Spring Boot application for which I keep a base application.properties, and then a couple of application-${profile}.properties files with configuration valid for several development environments.

I want to keep those application-${profile}.properties files in source control, but as they contain private development environment details, I want to be able to create a jar package without them for distribution to third parties (i.e. only with the base application.properties). This would force users to add their own application.properties to the classpath when executing (or configure in other ways), which is what I intend.

I understand I could move those profile configuration files elsewhere instead of src/main/resources so that mvn package ignores them, then add such folder to the classpath in IDE configurations... but I think there probably is a more integrated, elegant way of doing this with Boot that I'm missing...

Upvotes: 0

Views: 2759

Answers (1)

diyoda_
diyoda_

Reputation: 5420

I have not done it myself but according to the documentation, the application is reading properties from following locations

  1. A /config subdirectory of the current directory.
  2. The current directory A classpath /config package
  3. The classpath root

Then you can do

java -jar myproject.jar --spring.config.name=nameofpropertiesfile

Upvotes: 2

Related Questions