What’s new in Spring Boot 2.2?

Tim van Baarsen
7 min readOct 18, 2019

This week (October 16th, 2019) Spring Boot 2.2 has been released 🚀👏!
In this blog post, you will learn about the many new goodies version 2.2 offers you.

Maven

To get started with Spring Boot 2.2. in your application update to the new version of the starter parent.

In case you are starting an application from scratch, create a Maven or Grade project at start.spring.io!

Global Lazy bean initialization

Lazy initialization of beans is supported for a long time now by the Spring Framework.

A lazy-initialized bean tells the IoC container to create a bean instance when it is first requested, rather than at startup.

A new feature introduced by Spring Boot 2.2 is the support for global lazy bean initialization (by default this is disabled).

What happens when you enable global lazy bean initialization?

  • The initialization of all Spring beans and their dependencies will be delayed until the time they are needed.

To reduce your application startup time, you can now enable global lazy initialization Spring beans in properties file configuration using:

or for configuration in yml:

Are there downsides of using lazy bean initialization? Yes! It’s essential to understand the consequences, and you should only enable global bean initialization with care! There are some tradeoffs to consider:

  • Handling of HTTP requests may take longer while any deferred initialization occurs. Subsequent requests are not affected.
  • Failures that would typically occur at startup (because the Spring beans, and their dependencies, are created when the application context is created) will now not occur until later. So your application will not fail fast at startup anymore! The consequence: your customer might be the first one to face a (bean wiring) issue.

In case you don’t want to enable lazy bean initialization (spring.main.lazy.initialization=false) on a global level, you can consider configuring lazy initialization for a specific bean using the @Lazy annotation.

The other way around is also possible to enable lazy bean initialization (spring.main.lazy.initialization=true) on a global level. And explicitly disable lazy initialization for a specific bean.

To summarize:

JMX disabled by default

Since Spring Boot 2.2, JMX is disabled by default. This helps to improve the startup time of your application and won’t waste the consumption of a significant amount of resources at runtime. In case you depend on JMX you can enable it again:

or:

Configuration property improvements

Spring Boot 2.2 comes with some nice enhancements for configuration properties.

  • Classpath scanning support for @ConfigurationProperties
  • Immutable @ConfigurationProperties binding

Classpath scanning support for @ConfigurationProperties

Spring Boot will create a bean for each configuration class annotated with @ConfigurationProperties found via classpath scanning. This is an alternative to using

  • @EnableConfigurationProperties on the class wiring the properties class
  • or using the @Component annotation on a configuration class to make it a bean.

Be aware that two beans may be created for a configuration class that is annotated with both @Component and @ConfigurationProperties. In such cases, @Component should be removed from your configuration class!

Immutable @ConfigurationProperties binding

Immutable configuration property classes are now supported using constructor-based properties binding. Constructor-based binding can be enabled by annotating a @ConfigurationProperties class or one of its constructors with @ConstructorBinding.

Example:

properties in my application.yml:

For more details, see the documentation.

Actuator Endpoint changes

The /actuator/health endpoint has changed the resulting JSON format by renaming details to components for the first-level elements.

The actuator media type has been changed from: application/vnd.spring-boot.actuator.v2+json to application/vnd.spring-boot.actuator.v3+json.

Example Pre Spring Boot 2.2 (Actuator V2) /actuator/health endpoint response:

Spring Boot 2.2 (Actuator V3) /actuator/health endpoint response:

Your tooling might be depending on the health actuator V2 format.
The Spring Boot 2.2 health is backward compatible with the by specifying an HTTP Accept: header with the V2 media type, application/vnd.spring-boot.actuator.v2+json

You can try it out yourself using curl:

curl -H "Accept: application/vnd.spring-boot.actuator.v2+json" http://localhost:8080/actuator/health

Next to this change, it is now also possible to organize health indicators into groups.

RSocket support

RSocket is a binary protocol for use on byte stream transports. It enables symmetric interaction models via async message passing over a single connection.

Extensive auto-configuration has been added for RSocket along with a new starter.

For more details read the RSocket Spring Boot Documentation.

Java 13 support

Java 13 was released on the 17th of September 2019.

Spring Framework 5.2 and Spring Boot 2.2 now supports Java 13.
LTS Java versions 8 and 11 will remain compatible with Spring Boot 2.2.

Cloud Platform Kubernetes detection

ConditionalOnCloudPlatform now detects if your Spring Boot application is running on Kubernetes.

Banners

Spring Boot comes with a default banner, which is shown in the console as soon as the application starts.

A bit of a geeky feature, but Spring Boot already has support for (animated) custom banners.

Since Spring Boot 2.2 you can even make your banner look nicer 😁:

  • ASCII banner files can now make use of ANSI 256 color escape codes by using {AnsiColor.NNN} (where NNN is the color code).
  • For (animated) image banners you can now set the spring.banner.image.bitdepth property to 8. And the spring.banner.image.pixelmode property to block to use ASCII block chars.

The result looks like this:

Source: https://github.com/spring-projects/spring-boot/wiki/images/animated-ascii-art-256.gif

For a simple Spring Boot 2.2 improved animated banner example see my Github example project.

Java EE to Jakarta EE migration

Where possible, the Spring (Boot) team moved from Java EE dependencies with a javax. group ID to the equivalent Jakarta EE dependencies with a jakarta. group ID in Spring Boot’s starters.

Also, dependency management for the Jakarta EE API dependencies has been added alongside the existing dependency management for the Java EE API dependencies.

Keep in mind the dependency management for the Java EE API dependencies will be removed in the future versions of Spring Boot and you are encouraged to start using the Jakarta EE API dependencies.

Configuration (key) changes

Spring Boot 2.2 introduces many new configuration keys. There are also keys deprecated and removed. There are just too many changes to mention them all but here are some important ones:

  • logging.file property has been renamed to logging.file.name
  • logging.path property has been renamed to logging.file.path

For a complete overview of all the configuration changes check out the Spring Boot 2.2 configuration changelog!

Deprecations

Check the release notes for a complete list of deprecations on classes and properties.

Other deprecations to be aware of:

  • Joda time support is deprecated in favor of java.time
  • Both Elasticsearch transport client and Jest clients are deprecated in favor of other options, such RestHighLevelClient and ReactiveElasticsearchClientsee the documentation for more details

Dependency upgrades

Spring Boot 2.2 comes with many dependency upgrades.

Spring related dependency upgrades:

Most important other dependencies upgrades:

Test dependencies upgrades:

Migration to Spring Boot 2.2

Since August 1st, 2019 Spring Boot 1.x is end-of-life. In case you are still running Spring Boot 1.x applications, it’s time to upgrade!

Be aware classes, methods and properties that were deprecated in Spring Boot 2.1 have been removed in Spring Boot 2.2. Please ensure that you aren’t calling deprecated methods before upgrading. For deprecations in Spring Boot 2.1 check the release notes.

For more information check the:

Tap the 👏 button if you found this article useful!

Any questions or feedback?
Reach out to me on Twitter: @TimvanBaarsen

--

--

Tim van Baarsen

I’m a creative and passionate software developer living in the Netherlands. Occasional meetup & conference speaker.