How do I activate a Spring Boot profile when running from IntelliJ?

Cover Image for How do I activate a Spring Boot profile when running from IntelliJ?
Matheus Mello
Matheus Mello
published a few days ago. updated a few hours ago

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:

  1. Open your IntelliJ project.

  2. 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...".

  3. Select your desired run configuration for the Spring Boot application.

  4. In the "Configuration" tab, find the "Environment" section.

  5. Add a new environment variable named SPRING_PROFILES_ACTIVE.

  6. Set the value of SPRING_PROFILES_ACTIVE to the desired profile you want to activate (e.g., local, dev, qc, etc.).

  7. 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! โค๏ธ


More Stories

Cover Image for How can I echo a newline in a batch file?

How can I echo a newline in a batch file?

updated a few hours ago
batch-filenewlinewindows

๐Ÿ”ฅ ๐Ÿ’ป ๐Ÿ†’ Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Matheus Mello
Matheus Mello
Cover Image for How do I run Redis on Windows?

How do I run Redis on Windows?

updated a few hours ago
rediswindows

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! ๐Ÿš€ Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Matheus Mello
Matheus Mello
Cover Image for Best way to strip punctuation from a string

Best way to strip punctuation from a string

updated a few hours ago
punctuationpythonstring

# The Art of Stripping Punctuation: Simplifying Your Strings ๐Ÿ’ฅโœ‚๏ธ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Matheus Mello
Matheus Mello
Cover Image for Purge or recreate a Ruby on Rails database

Purge or recreate a Ruby on Rails database

updated a few hours ago
rakeruby-on-railsruby-on-rails-3

# Purge or Recreate a Ruby on Rails Database: A Simple Guide ๐Ÿš€ So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? ๐Ÿค” Well, my

Matheus Mello
Matheus Mello