How do I activate a Spring Boot profile when running from IntelliJ?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Spring Boot profiles let you keep one codebase while switching configuration for local development, testing, staging, or production. When you run the app from IntelliJ IDEA, the active profile is usually set through the run configuration rather than by editing source files.
What a Spring Profile Actually Changes
A profile tells Spring Boot which profile-specific properties and beans should be active. For example, dev might use an in-memory database and verbose logging, while prod might use a real database and stricter settings.
Typical configuration files look like this:
When the dev profile is active, values from application-dev.properties override the defaults where the keys overlap.
The Easiest IntelliJ Method: Program Arguments
For local development, the clearest way to activate a profile in IntelliJ is usually a program argument.
Open:
RunEdit Configurations- your Spring Boot run configuration
Then add this in Program arguments:
When you run the application, Spring Boot reads that argument just as it would from the command line.
This is a good default because the chosen profile is obvious in the run configuration, easy to change per developer, and easy to duplicate for multiple setups such as dev, test, or qa.
Other IntelliJ Options: Environment Variables and VM Options
You can also activate a profile with an environment variable:
Set that in the run configuration's environment section.
Another option is a JVM system property in VM options:
All three methods work. The real question is which one your team wants to standardize on.
Practical rule:
- use program arguments when you want the Spring Boot style to be explicit
- use environment variables when you want local runs to resemble containers or deployment systems
- use VM options only when the team already manages runtime flags there
Verify the Profile at Startup
Do not assume the profile was applied correctly just because IntelliJ shows the run configuration you expected. Print or log the active profile at startup.
That small check saves time when multiple configuration sources compete with each other.
You can also prove that profile-specific beans are switching correctly:
Running with dev activates the mock implementation, while prod activates the real one.
Keep Test Profiles Separate
IntelliJ run profiles are for application launches, but test classes should usually declare their own profile explicitly. That prevents local IDE settings from accidentally changing test behavior.
That way, test execution stays stable whether the developer is currently running the app with dev or some other profile.
Common Pitfalls
The most common problem is setting the profile in more than one place and forgetting that Spring Boot has precedence rules. If Program arguments, environment variables, and VM options all define a profile, debugging becomes harder than it needs to be.
Another issue is editing application.properties to hard-code a local profile for convenience. That tends to leak machine-specific behavior into the project.
Developers also often forget to verify the active profile at startup. If the wrong configuration file is loaded, the app can look broken for reasons that are really just configuration mismatch.
Finally, avoid keeping secrets directly in committed profile files. Use environment variables, secret management, or external configuration for credentials and tokens.
Summary
- In IntelliJ, the simplest way to activate a Spring profile is usually
--spring.profiles.active=dev. - You can also use
SPRING_PROFILES_ACTIVEor-Dspring.profiles.active=.... - Verify the active profile at startup instead of assuming the IDE configuration worked.
- Use profile-specific beans and property files to separate environment behavior cleanly.
- Keep test profiles explicit and keep secrets out of committed config files.
Related reading
- How do I add a newline to a TextView in Android?
- How do I address unchecked cast warnings?
- How do I analyze a .hprof file?
- How do I apply the for-each loop to every character in a String?
- How do I assert equality on two classes without an equals method?
- How do I assert my exception message with JUnit Test annotation?
- How do I calculate someone's age in Java?
- How do I change log level in runtime without restarting Spring Boot application

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.