#REVIEW: What’s new in Spring Boot 2.2

Last Updated:  October 21, 2019 | Published: October 21, 2019

Almost one year after the release of Spring Boot 2.1, we get a new release: Spring Boot 2.2. The Spring Boot team continues to further improve performance, support the latest Java version and provide useful features. As there are a lot of updates with this release, I'm focussing on the most (from my point of view) important ones. For one of my projects we upgraded right after the release date and already use some features in production. You can find the full list of updates, new and noteworthy things, and deprecations, at the official release notes on GitHub.

Lazy initialization of beans in Spring Boot 2.2

You might remember the lazy initialization option for JPA repositories which was introduced with Spring Data Lovelace and Spring Boot 2.1 last year. One of the main reasons for this is to reduce startup time and initialize the repositories once they are requested. With Spring Boot 2.2 we can now configure global lazy initializations of our beans (not only JPA repositories) with:

Single beans can opt-out of this configuration with the @Lazy(false) annotation or while using a LazyIntializationExcludeFilter.

To provide you an example, I'm using a REST controller which injects a bean to provide data:

Next, the SampleService opts-out for the global lazy initialization:

When we now start the application, we see that the SampleService is initialized right ahead and our SampleEndpoint bean only once someone requests http://localhost:8080/hello:

Please note that this new feature comes at costs as the initial HTTP request might take longer due to deferred initialization. Furthermore, you detect failures while initializing your bean only during your application's runtime and not at startup time.

JUnit 5 by default

With Spring Boot 2.2 and spring-boot-starter-test we now get JUnit 5 by default. It's still possible to use JUnit 4 tests and also a mixture of JUnit 4 & 5 with the JUnit 5 vintage engine. Both versions are part of the spring-boot-starter-test dependency without further configuration.

However, if you plan to enforce the usage of only JUnit 5 for your application, you can exclude the junit-vintage-engine. This will also exclude the JUnit 4.12 dependency:

The pre-generated @SpringBootTest you get while using the Spring Initializr then needs to be re-written for JUnit 5:

Performance improvements with Spring Boot 2.2

With this Spring Boot release, there are several performance improvements besides the lazy initialization feature:

  • Hibernate’s entity scanning is now disabled as Spring Boot fully prepares a PersistenceUnit by scanning JPA entities
  • Binding large numbers of configuration properties are now way faster
  • Injection points in auto-configurations have been refined to only apply when a bean has to be created
  • Beans related to Actuator endpoints are now only created if the endpoint is both enabled and exposed (via JMX or HTTP)
  • The HTTP trace and auditing Actuator features are not enabled by default anymore to reduce memory consumption while using the default implementations
  • Tomcat’s MBean Registry is disabled by default, saving approximately 2MB of Heap memory

Further updates with this release

RSocket support

RSocket is now a first-class citizen for your Spring Boot application. There is now a dedicated Spring Boot starter for RSocket: spring-boot-starter-rsocket. With this starter, you get all the required dependencies for building an application with RSocket. Similarly, the RSocket strategies are auto-configured to provide the required infrastructure for encoding and decoding RSocket payloads using CBOR and JSON.

Furthermore, you'll get auto-configuration for Spring Security if the RSocket security module is on the classpath.

Actuator updates

The JSON format for the /actuator/health endpoint has changed by renaming the top-level details attribute to components. This helps to differentiate the actual details returned by a HealthIndicator as they also contain a details field. To use the old JSON format, you can request it with an HTTP accept header with the V2 media type, application/vnd.spring-boot.actuator.v2+json. The new media type is application/vnd.spring-boot.actuator.v3+json

In addition, you can configure when to show the components and their details from /actuator/health. The management.endpoint.health.show-components property works in a similar way to show-details. The available values are neverwhen_authorized or always.

You can use this, for example, to alway show the components of your health check, but the details only to authorized users:

A non-authorized user then gets the following output:

Whereas an authorized user gets details about each component:

It is now possible to group health indicators and organize them with a logical name. A good example of this feature is to differentiate between liveness and readiness checks.

Imagine you use a custom HealthIndicator to check the liveness of your application:

You can now configure a liveness group with your custom check and the DataSource check like the following:

The liveness group is then available at localhost:8080/actuator/health/liveness:

Kubernetes detection

You are now able to detect if your application is running inside a Kubernetes cluster with the ConditionalOnCloudPlatform annotation:

Support for Java 13

Spring Boot 2.2 now supports Java 8, 11, and 13.

Dependency upgrades with Spring Boot 2.2

Besides other dependency upgrades, theses are one of the most important ones:

  • Spring Data Moore 2.2.0: Further reactive support (transactions, Querydsl, etc.) and much more
  • Reactor Dysprosium 3.3.0: A lot to discover, take a look at the official release notes 
  • Spring Framework 5.2: aka Core Container Revisited, find a great talk by Juergen Hoeller itself here
  • Flyway 6.0: Start using the latest database (PostgreSQL 11 & 12, SQL Server 2019, etc.) versions and get now five years of support starting with their release (both for Community and Pro-Edition). Find further updates here
  • Spring HATEOAS 1.0: If you are looking for a great introduction to this topic, take a look at Oliver Drotbohm's talk on SpringOne
  • Spring Security 5.2: Great improvements for OAuth 2.0 (both client & resource server)
  • Jackson 2.10:  This fixes some of the CVEs with previous versions of Jackson
  • … and much more

If you are looking for the official release notes, have a look at the wiki page of Spring Boot.

You can find the source code for this example on GitHub.

Have fun using Spring Boot 2.2,


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Sign up for Our Mailing List And Get

the Testing Java Applications ($9) Cheat Sheet for Free

Testing Java Applications Cheat Sheet Cover