# Add Spring support to existing project

IntelliJ IDEA automatically detects Spring in your project based on the XML configuration or `@Configuration` annotations. Normally, a Spring project does not require manual configuration, and most of the features are available without adding the Spring facet.

However, if you have multiple Spring application contexts, you have to map existing configuration files to application contexts so that IntelliJ IDEA provides correct coding assistance and enables gutter icons in bean definitions. The IDE will inform you if the project requires additional configuration, and a warning will be displayed on top of a configuration file if it is not mapped to any application context. You can also check the Spring configuration using [the dedicated action](#check-spring-configuration). To map you configuration files to application contexts, you have to do the following:

* In the project settings, [add the Spring facet](#add-spring-facet).

* [Create application contexts](#create-application-context).

Procedure: Add Spring facet

1. In the main menu, go to `File | Project Structure…` or press `Ctrl+Alt+Shift+S` (Windows), `⌘ ;` (macOS), `⌘ ;` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ Comma` (macOS System Shortcuts), `Ctrl+Alt+Shift+S` (XWin), `Ctrl+Alt+Shift+S` (GNOME), `Ctrl+Alt+Shift+S` (KDE), `Ctrl+Alt+Shift+S` (Emacs), `Ctrl+Alt+Shift+S` (Sublime Text), `⌘ ;` (Sublime Text (macOS)), `Ctrl+Alt+Shift+S` (NetBeans), `Ctrl+Alt+Shift+S` (Visual Studio), `⌘ ;` (Visual Studio (macOS)), `Ctrl+Alt+Shift+S` (Eclipse), `⌘ ;` (Eclipse (macOS)) to open the Project Structure dialog.

2. From the left-hand list, select Modules.

3. Select the necessary module and click ![The Add button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.add.svg) in the middle section.

4. Select Spring from the list.

At this point, you may already see autodetected contexts and configuration files as well as unmapped files.

![Spring Add Facet](https://resources.jetbrains.com.cn/help/img/idea/2026.2/spring_add_facet.png)

Procedure: Create application contexts

1. In the project structure (`Ctrl+Alt+Shift+S` (Windows), `⌘ ;` (macOS), `⌘ ;` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ Comma` (macOS System Shortcuts), `Ctrl+Alt+Shift+S` (XWin), `Ctrl+Alt+Shift+S` (GNOME), `Ctrl+Alt+Shift+S` (KDE), `Ctrl+Alt+Shift+S` (Emacs), `Ctrl+Alt+Shift+S` (Sublime Text), `⌘ ;` (Sublime Text (macOS)), `Ctrl+Alt+Shift+S` (NetBeans), `Ctrl+Alt+Shift+S` (Visual Studio), `⌘ ;` (Visual Studio (macOS)), `Ctrl+Alt+Shift+S` (Eclipse), `⌘ ;` (Eclipse (macOS))), under `Project Settings | Facets`, select the added Spring facet.

2. Click ![The Add button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.add.svg) to create a new context.

3. In the New Application Context dialog, specify the name for context and select the configuration files that should be used in the context (either XML files or source code files annotated with `@Configuration`).

![Spring Add Facet](https://resources.jetbrains.com.cn/help/img/idea/2026.2/spring_add_application_context.png)

If your project is correctly configured, you will see Spring gutter icons marking each component, bean, and so on. To configure gutter icons, open the IDE settings with `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) and go to `Editor | General | Gutter Icons`.

Procedure: Check Spring Configuration

If you have unmapped configuration files, the corresponding warning will be displayed in `File | Project Structure…` and on top of the configuration file when opened in the editor. If in doubt, you can check the Spring configuration using the dedicated action.

1. Press `Shift` (Windows), `Shift` (macOS), `Shift` (IntelliJ IDEA Classic (macOS)), `Shift` (macOS System Shortcuts), `Shift` (XWin), `Shift` (GNOME), `Shift` (KDE), `Shift` (Emacs), `Shift` (Sublime Text), `Shift` (Sublime Text (macOS)), `Shift` (NetBeans), `Shift` (Visual Studio), `Shift` (Visual Studio (macOS)), `Shift` (Eclipse), `Shift` (Eclipse (macOS)) twice to open the search window and go to the Actions tab or just press `Ctrl+Shift+A` (Windows), `⌘ ⇧ A` (macOS), `⌘ ⇧ A` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ P` (macOS System Shortcuts), `Ctrl+Shift+A` (XWin), `Ctrl+Shift+A` (GNOME), `Ctrl+Shift+A` (KDE), `Escape, X` (Emacs), `Ctrl+Shift+P` (Sublime Text), `⌘ ⇧ P` (Sublime Text (macOS)), `Ctrl+I` (NetBeans), `Ctrl+Shift+A` (Visual Studio), `⌘ ⇧ A` (Visual Studio (macOS)), `Ctrl+Shift+A` (Eclipse), `⌘ 3` (Eclipse (macOS)).

2. In the search field, type Check Spring Configuration and select the corresponding action. If your project has unmapped configuration files, a notification will be displayed.

3. Click the link with the number of unmapped files (for example, 2 files) and select one of the files. This will open the file in the editor where you can either select one of the available contexts or [create a new one](#create-application-context).

## Configure a parent context

IntelliJ IDEA allows you to configure a parent-child relationship between contexts. Beans from a parent context are visible to beans in child contexts, but not vice versa. Therefore, beans from child contexts can use configuration from the parent context.

For example, Spring MVC applications usually have two contexts: one for the web layer beans and the other for services and repositories. The web layer context will be a child context in this case, as you need to inject services into controllers, not the other way around.

To configure a parent context, use the New Application Context dialog, as described in [Create application contexts](#create-application-context).

The Multiple Contexts panel shows up on top of the editor for files included in two or more application contexts. You can use this panel to select the active context, for example, if you want to run your application with a specific configuration, and change highlighting. To disable the panel, click ![The Settings button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.general.settings.svg) and clear the Show Multiple Contexts panel checkbox.

> **Note:**
> IntelliJ IDEA can configure the parent context automatically. For example, if the IDE detects the Spring Cloud context, it will make it a parent application context for Spring Boot.

## Change active profiles

Spring allows you to map specific contexts or beans to different profiles, for example, test or production. This way, you can activate different profiles in different environments.

If you have defined at least one profile in your project, IntelliJ IDEA will show a special panel on top of the editor in configuration bean files. You can use this panel to view the current profile name and change active profiles.

> **Tip:**
> You can also change active profiles in the [Spring tool window](spring-tool-window.html). Right-click a component and select Change Active Spring Profiles.

Procedure: Change active profiles

1. Click Change Profiles on the panel.

2. Select the component to which you want to map the profile. This can be either the entire project, the current module, or the current context.

3. Select the profile to which you want to map this component.

![Changing the Spring profile](https://resources.jetbrains.com.cn/help/img/idea/2026.2/spring_change_profiles.png)

If you want to hide the panel, click ![The Settings button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.general.settings.svg) and clear the Show Profiles Panel checkbox.

Procedure: Share facet settings

You can change and share settings by creating custom facets and adding a module file with the `.iml` extension to the version control system.

For example, to share an application context within your team, you can create a Spring facet and commit its settings.

1. In the main menu, go to `File | Project Structure` or press `Ctrl+Alt+Shift+S` (Windows), `⌘ ;` (macOS), `⌘ ;` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ Comma` (macOS System Shortcuts), `Ctrl+Alt+Shift+S` (XWin), `Ctrl+Alt+Shift+S` (GNOME), `Ctrl+Alt+Shift+S` (KDE), `Ctrl+Alt+Shift+S` (Emacs), `Ctrl+Alt+Shift+S` (Sublime Text), `⌘ ;` (Sublime Text (macOS)), `Ctrl+Alt+Shift+S` (NetBeans), `Ctrl+Alt+Shift+S` (Visual Studio), `⌘ ;` (Visual Studio (macOS)), `Ctrl+Alt+Shift+S` (Eclipse), `⌘ ;` (Eclipse (macOS)). Then select Modules.

2. Make sure the module to which you want to add a facet is selected and click ![the Add button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.general.add.svg) above the list of modules. From the list of available facets, select Spring.

![Adding Spring facet](https://resources.jetbrains.com.cn/help/img/idea/2026.2/add_spring_facet.png)

3. In the right section, click ![the Add button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.general.add.svg) to add a new application context.

4. Name the context, click ![the Add button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.general.add.svg), select a context type, and then select the file on your computer.

5. Reopen the project. After that, the changes will appear in the `.iml` file of the module to which you have added the facet.

![Spring facet in module file](https://resources.jetbrains.com.cn/help/img/idea/2026.2/spring_facet_iml.png)

6. [Add the .iml file](adding-files-to-version-control.html#add-files-to-vcs) to your version control system.

