IntelliJ IDEA 2018.1 Help

Spring Boot

Get started with Spring Boot

Spring Initializr is a wizard that allows you to select the necessary configuration when you are creating a project or a module. For example, you can select a build tool, and add Spring Boot starters and dependencies.

To access the wizard, go to File | New | Project or Module, and select Spring Initializr. Follow the steps of the wizard to select technologies and dependencies you want to use.

Spring Initializr will create a project with a defined build file (pom.xml or build.gradle ), a source file, a test file, and an empty application.properties file. If you have previously configured advanced code formatting settings, they will be applied to the predefined files. If you want Spring Initializr to create a project with the default code formatting settings, open the Settings/Preferences dialog, go to Languages & Frameworks | Spring | Spring Boot and disable the Reformat Code option.

Configure custom configuration files

Spring Initializr creates one default configuration file that may not always be sufficient for development. If you do not want to use the default configuration file, or if you want to run your code in different environments, you can use custom configuration files.
To do so, you have to let IntelliJ IDEA know which files are configuration files in you project. This will enable relevant highlighting and coding assistance.

  1. Go to File | Project Structure | Facets.
  2. Click spring boot icon (Customize Spring Boot) in the toolbar.
  3. If you want to use a custom configuration file instead of the default one, type in the name of a new custom configuration file in the search box.

    If you want to use multiple configuration files, click add and select files from the project tree.

  4. Click OK and apply the changes.
spring boot custom config

If a custom configuration file is set up correctly, it will be marked with the spring boot icon icon.

Run and monitor Spring Boot applications

Spring Boot has built-in features that allow you to get key metrics and monitor the state of your application in the production environment by invoking different endpoints, such as health or bean details.
In IntelliJ IDEA, you can view endpoints on the Endpoints tab. This tab appears on the Run dashboard, or in the Run/Debug tool window when you run an application.

Enable the Run dashboard

  1. From the main menu, select Run | Edit Configurations.
  2. Select Defaults.
  3. Under the Configurations available in Run dashboard section, click add.
  4. Select Spring Boot and apply the changes.

To show or hide the dashboard, go to View | Tool Windows and click Run dashboard.

The Endpoints tab becomes available if the Enable JMX agent checkbox is selected in the Run/Debug Configurations dialog.
Moreover, make sure to add the org.springframework.boot.spring-boot-starter-actuator dependency to your module before running your application. This will let IntelliJ IDEA access and display endpoints. For the mappings endpoint, add the org.springframework.boot.spring-boot-starter-web starter as well.

spring boot endpoints

When you run an application, the live beans gutter icon 181 icon shows up in the gutter on bean declarations indicating that beans are found in the context. You can use this icon to view dependent and injected beans.

If the icon doesn't appear, make sure the Enable JMX agent checkbox is selected in the Run/Debug Configurations dialog.

Access HTTP request mappings from the editor

After you run your Spring Boot Web application, the live request mapping gutter icon will appear in the gutter for methods with @RequestMapping annotations to indicate that they are registered as handlers by Spring.

Click this icon to choose the next action. You can run the request straight away, or you can open it in a scratch file with the HTTP extension in the editor, where you can edit it if necessary, and then run via the REST client. For methods with @GetMapping annotations, you can also open the mapped URLs in a browser.

request mappings

Configure application update policies with devtools

With the spring-boot-devtools module, your application will restart every time files on the classpath change. However, if you want your application to restart only at specific moments, you can set a trigger file. In this case your application will restart only after you modify the trigger file.

IntelliJ IDEA provides more options for updating a running application. After you enable the devtools, the Update <application name> Application update running app icon option (Ctrl+F10) becomes available on the left frame of the Run dashboard, in the Run/Debug tool window, and from the main menu (Run | Update <application name> Application). Depending on your needs, you can configure what the IDE will do after you click this option.

  1. From the main menu, select Run | Edit Configurations.
  2. Select the necessary Spring Boot configuration, or create a new one (click add and select spring boot icon Spring Boot).
  3. Specify the main class that this configuration must be applied to.
  4. From the On 'Update' action list, select a policy. You can update resources only, update classes and resources (build your application), update the trigger file (restart), or perform a class hot swap, and if it fails, IntelliJ IDEA will update the trigger file (restart).

From the On frame deactivation list, you can also select an action that the IDE will do after you switch to another application. IntelliJ IDEA can update resources, or build your application.

Last modified: 24 July 2018

See Also