Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default environment in Spring Boot

How can I set the default environment in Spring Boot?

I put in application.properties:

spring.profiles.include=prod,dev
spring.profiles.active=prod

and in user variables:

SPRING_PROFILES_ACTIVE = dev

So when I dev in my comp my environment are dev but when I generate my .war and deploy in tomcat he still using dev with enviroment (I deploy in another comp with no other conf)

How can I set my default environment (if he don't find any in user variables or commmand line uses production)?

like image 639
Fabio Ebner Avatar asked Aug 06 '15 20:08

Fabio Ebner


1 Answers

What you need is:

1) Define the active profile you need, something like:

spring.profiles.active=dev

In this example the loaded file will be application-dev.properties

Now, if you need to switch to a different environment depending where are you installing your war file what you can do is to set this variable as a system variable in each environment you want, that way each environment has a different value for the same key, something like:

-Dspring.profiles.active=dev

In my case I am using Tomcat and I declare this key/value in the file setenv.sh, you need to assign that value depending on the server you're using.

like image 168
Eduardo Avatar answered Oct 08 '22 19:10

Eduardo