Spring
Spring is an application framework for the Java platform. It helps you build modern web applications with support for microservice architectures, cloud systems, reactive processing, and serverless workloads.
IntelliJ IDEA provides extensive coding assistance for Spring, including a dedicated project wizard, code highlighting, intelligent context actions, embedded documentation, navigation, and highly customizable run configurations. For a detailed description of the supported features, see this page on the JetBrains web site.
If you are new to Spring, start with Tutorial: Create your first Spring application.
To use Spring in your project, you need the Spring facet that comprises libraries and UI elements for configuring settings specific to Spring. IntelliJ IDEA automatically detects Spring configuration files in your code. The IDE will inform you if the project requires any adjustments and suggest the necessary actions. So normally, a Spring project does not require manual configuration.
However, if IntelliJ IDEA does not detect configuration files automatically, you can add the facet manually:
Manually add Spring support to existing modules
From the main menu, select Project Structure dialog.
or press Ctrl+Alt+Shift+S to open theFrom the left-hand list, select Modules.
Select the necessary module and click in the middle section.
Select Spring from the list.
Select the necessary library.
If you already have a Spring library, select Use library and specify the library that you want to use.
If you have the corresponding JAR files, click Create… and select the files to arrange into a new library.
If you do not have a library, select Download.
Whatever option you choose, you can click Configure… to edit the selected library settings and contents.
When you are done, click OK to add the facet to the module.
If the Spring facet is configured correctly, 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 and go to
.Create an application context
The Spring application context is a way of grouping configuration files in IntelliJ IDEA. When you create a context, you let IntelliJ IDEA understand the relationship between configuration files included into this context.
You can create as many application contexts as you need and add any configuration file in more than one context.
From the main menu, select Project Structure dialog.
or press Ctrl+Alt+Shift+S to open theFrom the left-hand list, select Facets.
Select the Spring facet from the list in the middle and click in the right-hand section.
In the New Application Context dialog, specify the name for context and select the files you want to include in the 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 an application context.
The Multiple Contexts panel shows up on top of the editor for files included into 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 and clear the Show Multiple Contexts panel checkbox.
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. You can use this panel to view the current profile name and change active profiles.
Click Change Profiles on the panel.
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.
Select the profile to which you want to map this component.
If you want to hide the panel, click and clear the Show Profiles Panel checkbox.