2

I am pretty new to spring boot, We are working on a spring boot application(packaging as a war file). When deploying this war file in higher environments on a tomcat server, 1. Can we configure the application.properties for diff environments inside the war (Be it dev, int, uat, prod)? OR 2. When application.properties is configured can we put that in a conf folder in tomcat, Outside the war file. (Similar to putting a context.xml in a traditional web application) and the app will still pick it up?

PragmaticFire
  • 65
  • 1
  • 1
  • 11
  • 1
    https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config – JB Nizet Oct 27 '18 at 19:15
  • @JBNizet Thanks for the link, My question here is once I configure profile specific properties, Can we put them in conf folder(In Tomcat) outside the war file to load them? – PragmaticFire Oct 27 '18 at 19:31
  • You can put them everywhere the documentation I linked to explains. – JB Nizet Oct 27 '18 at 19:33

2 Answers2

6

Yes, you can set different profiles for different environments. Let's assume we have dev, qa and prod environments. You need to create three files on same location where application.properties located with names like:

  • application-dev.properties for dev environment
  • application-qa.properties for qa environment
  • application-prod.properties for prod environment

Now, you just need to set spring.profiles.active=qa in application.properties. Currently, we set qa profile. You can set what you want.

Note The properties you set in new created profile will only available for active profile. For example, if you set some properties in dev file, it will only available only for dev environment. But properties set in application.properties will be available for all environment. So configurations which are not environment dependent can be placed in application.properties

Tayyab Razaq
  • 348
  • 2
  • 11
  • But this could be dangerous because you will have access to all the environments by just changing the `spring.profiles.active` in `application.properties`. I think it is safer to deploy for each environment rather than have them all in the same place. – Somebody Jul 29 '20 at 18:59
1

You can configure different Profiles for your environments. For your dev-Environment you can add an application-dev.properties (or .yml) or for PROD an application-prod.properties, then just start your application with that Profile.

See https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html

Robert Freese
  • 71
  • 1
  • 1
  • 4