Setting the default active profile in Spring-boot

We Are Going To Discuss About Setting the default active profile in Spring-boot. So lets Start this Java Article.

Setting the default active profile in Spring-boot

  1. Setting the default active profile in Spring-boot

    What you are doing here is setting the default default profile (the profile that is used on any bean if you don't specify the @Profile annotation) to be production.

  2. Setting the default active profile in Spring-boot

    What you are doing here is setting the default default profile (the profile that is used on any bean if you don't specify the @Profile annotation) to be production.

Solution 1

What you are doing here is setting the default default profile (the profile that is used on any bean if you don’t specify the @Profile annotation) to be production.

What you actually need to do is set the default active profile, which is done like this:

spring.profiles.active=production

Original Author PaulNUK Of This Content

Solution 2

add --spring.profiles.active=production

Example:

java -jar file.jar --spring.profiles.active=production

Original Author Jaya Naresh Of This Content

Solution 3

First of all, with the solution below, is necessary to understand that always the spring boot will read the application.properties file. So the other’s profile files only will complement and replace the properties defined before.

Considering the follow files:

application.properties
application-qa.properties
application-prod.properties

1) Very important. The application.properties, and just this file, must have the follow line:

[email protected]@

2) Change what you want in the QA and PROD configuration files to see the difference between the environments.

3) By command line, start the spring boot app with any of this options:

It will start the app with the default application.properties file:

mvn spring-boot:run

It will load the default application.properties file and after the application-qa.properties file, replacing and/or complementing the default configuration:

mvn spring-boot:run -Dspring.profiles.active=qa

The same here but with the production environment instead of QA:

mvn spring-boot:run -Dspring.profiles.active=prod

Original Author Rafael S. Fijalkowski Of This Content

Solution 4

We to faced similar issue while setting spring.profiles.active in java.

This is what we figured out in the end, after trying four different ways of providing spring.profiles.active.

In java-8

$ java --spring.profiles.active=dev -jar my-service.jar
Gives unrecognized --spring.profiles.active option.
$ java -jar my-service.jar --spring.profiles.active=dev
# This works fine
$ java -Dspring.profiles.active=dev -jar my-service.jar
# This works fine
$ java -jar my-service.jar -Dspring.profiles.active=dev
# This doesn't works

In java-11

$ java --spring.profiles.active=dev -jar my-service.jar
Gives unrecognized --spring.profiles.active option.
$ java -jar my-service.jar --spring.profiles.active=dev
# This doesn't works
$ java -Dspring.profiles.active=dev -jar my-service.jar
# This works fine
$ java -jar my-service.jar -Dspring.profiles.active=dev
# This doesn't works

NOTE: If you’re specifying spring.profiles.active in your application.properties file then make sure you provide spring.config.location or spring.config.additional-location option to java accordingly as mentioned above.

Original Author mchawre Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment