Priya
Priya

Reputation: 1226

Externalizing configuration for a Spring boot war file in Tomcat

I have a Spring boot web application deployed to tomcat's webapps directory. I also have the profile based application-<profile>.properties file. How to make the profile to be set automatically for dev,staging and prod environments. How to achieve this using Tomcat and how to make it to be chosen within the application itself without tomcat . It would be better if I am not setting the active profile in application.properties by default .

Upvotes: 1

Views: 1444

Answers (1)

Sudhakar
Sudhakar

Reputation: 3180

Spring Boot allows you to externalize your configuration so you can work with the same application code in different environments. You can use properties files, YAML files, environment variables and command-line arguments to externalize configuration.

Spring Boot uses a very particular PropertySource order that is designed to allow sensible overriding of values. Properties are considered in the following order:

  • Java System properties (System.getProperties()).
  • OS environment variables.

This can be achieved using system environment property:

  1. Add the below entry in environment variable in system.

    spring.profiles.active = dev

  2. Make sure that you have application-dev.properties in your boot project.

Upvotes: 1

Related Questions