/ SPRING BOOT, INTELLIJ IDEA, IDE

Spring Boot integration in IntelliJ IDEA

That’s one nifty feature, among others. If you’re developing with Spring Boot, IntelliJ IDEA does offer a lot more niceties to speed up development time. Let’s browse through some of them.

Project creation with the Initializr

Usually, creating a Spring Boot project requires:

  1. Going to the online Spring Initializr
  2. Selecting a few options
  3. Downloading the project archive
  4. Extracting the archive
  5. Importing it into the IDE

IntelliJ IDEA makes it a lot simpler by providing a GUI through which to do the previous steps. Go to File  New  Project…​. Select Spring Initializr and follow the wizard.

Spring Initialize wizard
The wizard doesn’t work offline, it requires access to start.spring.io (or at least access to the Spring Initializr instance used).

Spring Boot run/debug configurations

It’s perfectly possible to use a standard Application configuration to run Spring Boot applications.

However, the dedicated Spring Boot configuration allows specific options:

  • Enable debug output
  • Hide Banner
  • Enable launch optimization
  • Enable JMX agent
  • Set Active Profiles
  • Override parameters
Spring Boot specific run configuration

To create such a configuration, go to Run  Edit Configurations…​. Then, on the right top corner, click on the + button. Finally, fill in the fields adequately.

Application configuration properties auto-completion

In the application.properties file, standard properties can be auto-completed. For example, if one starts typing "log", available options will be displayed automatically.

Even better, IntelliJ IDEA warns if a property is not recognized.

Warning is displayed if a property is not recognized

A property is "recognized" if an associated XXXProperties class is on the classpath (and referenced by a spring-configuration-metadata.json). However, since the spring-boot-autoconfigure.jar has all properties and the later file, it doesn’t help much for standard JARs: e.g. one could use a spring.jpa property without spring-data-jpa.jar on the classpath.

It will work for your own if you package the Properties class and the configuration files within your JAR.

Application configuration YAML auto-completion

application.yml benefits from the same auto-completion feature as properties.

Application configuration files setter

Context files of regular Spring projects can be set in the project settings. Spring Boot configuration properties can be also set, in case the default application.properties is not the right fit.

Right-click on the project. Choose Open Module Settings…​. In the opening window, select Modules  <app    Spring. Click on the Spring Boot icon at the bottom.

Application configuration files setter

The pattern of the application configuration file can set to override the default one.

This is different than setting the application configuration files are runtime. This allows IntelliJ IDEA to manage it at compile-time.

Actuator integration

I believe that the Actuator is one of the best feature in Spring Boot, if not the best. IntelliJ IDEA offers a great integration of it.

The Run dashboard is able to display a lot of data, taken from the Actuator:

Beans
Spring Boot Run dashboard - Beans tab
Health
Spring Boot Run dashboard - Health tab
Controller mappings
Spring Boot Run dashboard - Mappings tab

Triggering DevTools

This is not an integration feature, but rather a workaround I found.

DevTools is a dependency that allows to update a Spring Boot app during development without restarting the whole Tomcat (and more). It works by detecting when a class is compiled and replaced and reloading part of the context. By default, IntelliJ IDEA saves automatically changed files but doesn’t compile (as opposed to Eclipse which requires saving explicitly but then compiles).

Thus, to trigger reloading, one needs to click every time on the Build Project button. Instead, I assigned a keyboard shortcut i.e. +Shift+S which emulates Eclipse behavior.

Conclusion

While Spring Tools Suite is the "official" Spring IDE, IntelliJ IDEA offers a lot of niceties that speed up Spring Boot applications development time.

Nicolas Fränkel

Nicolas Fränkel

Nicolas Fränkel is a Developer Advocate with 15+ years experience consulting for many different customers, in a wide range of contexts (such as telecoms, banking, insurances, large retail and public sector). Usually working on Java/Java EE and Spring technologies, but with narrower interests like Software Quality, Build Processes and Rich Internet Applications. Currently working for Exoscale. Also double as a teacher in universities and higher education schools, a trainer and triples as a book author.

Read More