Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to choose profile in IntelliJ IDEA?

Why IntelliJ IDEA opens a message when I open Spring configuration file and drop-down to choose a profile? And why it doesn't appear anymore if I choose close link?


1 Answers

When you click "Close" on the profile pop-up, it makes a settings change and disables the panel for all spring contexts. (So you are not just closing it for that file and that viewing. IMHO "Close" is a bit of a misleading name. I think the "Close" link should be renamed to "Disable".) You can turn it back on via: File > Settings > [IDE Settings] > Editor > Appearance > "Show Spring Profiles panel" (it's near the bottom)

EDIT

This quirk in the UI has been annoying me for a while. Answering your question made me take a minute to open a usability -issue-report/feature-request to change it. Please vote for it.

EDIT 2 To answer your follow up question in your comment...

The setting is for the IDE only and does not effect anything when you run or test the code. Conversely, it does not pick up any settings from your code. It basically sets what you, IDEA, and IDEA's inspections "see". It makes it so only beans from the selected profile are "active in the IDE. This way you can switch between profiles when editing your code and configurations and get a valid representation of that profile.

For example, take a look at the screenshot below. (You may have to open it in a separate browser tab to see the detail.) In it I have the 'dev' profile active. By doing that I get the following benefits:

  1. IDEA highlights that it cannot resolve a bean that I am trying to reference that I have mistakenly only defined in the (non-active) 'prod' profile. (Or the error could be that the bean has a different name in each profile.)
  2. When I trigger code completion to reference another bean, IDEA only shows me beans that are available, including those in the active profile. Notice it does NOT show me the 'beanDefOnlyInProdProfile' bean since it is in an inactive profile. enter image description here

The same holds true in code completion when in Java Classes. Notice below the two code completions only show me beans from the active profile: enter image description here

like image 102
Javaru Avatar answered Jan 27 '26 08:01

Javaru



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!