How to Set a Default Environment in Spring Download

How to set default environment in spring boot?

I put application.properties :

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

and in user variables:

 SPRING_PROFILES_ACTIVE = dev 

So, when I debut in my comp, my environment is dev, but when I create my .war and deploy to tomcat, it still uses dev with the environment (I deploy to another comp without any other conf)

How can I set my environment by default (if it does not find any user variables or link production)?

+7
spring-boot environment-variables
source share
2 answers

See Spring's download guide for profile-specific profile properties

http://docs.spring.io/spring-boot/docs/1.3.0.BUILD-SNAPSHOT/reference/htmlsingle/#boot-features-external-config-profile-specific-properties

I will remove what you have from your application.properties. You say that you must include (not replace) both dev and prod profiles. Much easier to set up

  • application.properties (if no profile is specified)
  • application-dev.properties (for dev profile)
  • application-prod.properties (for prod profile)
+4
source share

What you need:

1) Define the active profile that you need, for example:

 spring.profiles.active=dev 

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

Now, if you need to switch to another environment, depending on where you install your war file, then what you can do is set this variable as a system variable in each environment you want, so each environment has a different meaning for same key, something like:

 -Dspring.profiles.active=dev 

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

+1
source share

All Articles