How do I activate a Spring Boot profile when running from IntelliJ?
How to Activate a Spring Boot Profile When Running from IntelliJ ๐
So, you want to activate a specific Spring Boot profile when running your application from IntelliJ? No worries, we've got you covered! ๐
The Problem ๐ค
Many developers face this common issue when trying to run their Spring Boot application using the Gradle plugin in IntelliJ. Despite setting the --spring.profiles.active
or -Dspring.profiles.active
parameters in the run configuration, the application fails to recognize the active profile. The INFO message indicates that "no active profile is set, falling back to default profiles: default."
The Solution ๐ก
Fortunately, there is a simple solution to this problem! Follow these steps to activate your desired Spring Boot profile:
Open your IntelliJ project.
Navigate to the "Run/Debug Configurations" menu. You can find it by clicking on the dropdown menu near the Run button or by going to "Run" -> "Edit Configurations...".
Select your desired run configuration for the Spring Boot application.
In the "Configuration" tab, find the "Environment" section.
Add a new environment variable named
SPRING_PROFILES_ACTIVE
.Set the value of
SPRING_PROFILES_ACTIVE
to the desired profile you want to activate (e.g.,local
,dev
,qc
, etc.).Click "Apply" and then "OK" to save the changes.
Testing, Testing ๐งช
Now, let's see if our changes actually work! Run your Spring Boot application using the Gradle plugin in IntelliJ, and keep an eye on the console output.
If everything went well, you should see the following INFO message:
The following profiles are active now: local
Congrats! ๐ You have successfully activated your Spring Boot profile when running the application from IntelliJ.
The Command Line Solution โจ๏ธ
If you prefer running your application from the command line, setting the SPRING_PROFILES_ACTIVE
environment variable before executing the Gradle command is also a viable option.
For example, if you want to activate the local
profile, use the following command:
set SPRING_PROFILES_ACTIVE=local && gradle bootRun
Call-to-Action ๐
Now that you know how to activate your Spring Boot profile when running from IntelliJ, go ahead and give it a try! Share your success stories, experiences, and any additional tips or tricks in the comments below. Let's help each other become Spring Boot profile activation masters! โค๏ธ