What’s new in Spring Boot 2.3?

Tim van Baarsen
8 min readMay 16, 2020

--

On May 15th, 2020, Spring Boot 2.3.0 was released 🎉. A big round of applause for the Spring Boot team 👏 . This new version of Spring Boot is packed with many new cool features! Check out my blog post to learn what’s new in Spring Boot 2.3.

Highlights of this release include:

  • Support for building Docker images using Cloud Native Buildpacks
  • Support for building layered jars for building optimized Docker images
  • Support for Java 14
  • End-to-end traceability for configuration properties
  • Support for (Kubernetes) liveness and readiness probes
  • Improved VMWare Tanzu Observability Wavefront support
  • GA Support for R2DBC
  • New condition annotation @ConditionalOnWarDeployment
  • Numerous dependency upgrades

Getting started

To get started with Spring Boot 2.3. 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!

Build Docker images using Cloud Native Buildpacks

You can now build a (Docker) image for your Spring Boot application in minutes without writing a Docker file!

Leveraging Cloud Native Buildpacks, you can turn your application source code into an OCI image using the Spring Boot Maven plugin

./mvnw spring-boot:build-image

or using the Spring Boot Gradle plugin:

./gradlew bootBuildImage

The Paketo Java buildpack is used by default to create images.

For a complete example and more details, check my previous blog post: “First look at Cloud Native Buildpacks support in Spring Boot 2.3” or the reference documentation.

You may drop your Dockerfile from your project now 😉

rm Dockerfile

Layered Jars

In case you prefer to stick with building Docker images yourself instead of using Cloud Native Buildpacks, Spring Boot 2.3 offers a nice feature for you to create optimized Docker images in an easier way.

Docker images consist of immutable layers identified by a sha256 hash that will never change. Each layer represents a Dockerfile instruction. The layers are stacked and each one is a delta of the changes from the previous layer. Once the image is built, you can view all the layers that make up the image using:

docker history <image>

When rebuilding a Docker image:
A change in an upper layer means Docker will only need to rebuild all subsequent layers the rest can be reused from the layer cache. The layers order is important as it determines how likely previous layers can be cached!

A fat jar of your Spring Boot applications contains your compiled code but also all dependencies that usually don’t change between releases.

Example: You change one line of code in your Spring Boot application. For this code change, all dependencies are copied over again into a new fat jar. When containerizing the application Docker will rebuild the layer that holds the new version of the fat jar. This is leading to a waste of space, bandwidth, and time.

Spring Boot 2.3 providing a smarter way to build ‘layered jars’ to make sure dependencies, spring boot jar loaders classes, and your compiled code end up in different layers.

A complete example is beyond the scope of this blog post but give it a try! Read the extensive reference documentation about layered jars.

End-to-end traceability for configuration properties

The /actuator/configprops endpoint exposes a list of all @ConfigurationPropertiesand is now aligning its behavior with the /actuator/env endpoint since Spring Boot 2.3.

Example of end-to-end traceability for custom configuration properties:

End-to-end traceability of configuration properties

Actuator Health improvements

Spring Boot 2.3 introduces liveness and readiness probes that can be exposed via the /actuator/health endpoint to improve deployments of Spring Boot applications on Kubernetes (although these endpoints are also very helpful for non-Kubernetes deployments).

  • Liveness: tells whether or not the internal state of your application is valid. /actuator/health/liveness
  • Readiness: tells whether or not your application is ready to accept client requests. /actuator/health/readiness

Enable the probes in your application.yml configuration:

When running your application on Kubernetes, the probes are enabled automatically.

For more details about check out the Kubernetes production-ready probes documentation.

Some other health actuator improvements:

New condition annotation

The new condition annotation @ConditionalOnWarDeployment can be used to detect whether or not an application has been deployed as a war to a Servlet container or application server.

GA support for R2DBC

R2DBC (Reactive Relational Database Connectivity) is an API specification initiative that declares a reactive API to be implemented by driver vendors to access their relational databases. R2DBC enables you to brings reactive programming (non-blocking) APIs to relational databases.

Spring Boot 2.3 introduces:

  • GA support for R2DBC
  • Spring Data R2DBC
  • Auto-configuration of the ConnectionFactory (when r2dbc is on the classpath)
  • Health indicator for ConnectionFactory
  • Metrics for the connection pool
  • Test slice @DataR2dbcTest

Be aware using R2DBC: the regular DataSource auto-configuration backs off so no schema.sql and data.sql will be loaded automatically!

Example: Spring Data R2DBC test slice example initializing the database

For more details check the Spring Boot documentation — Initialize a Database Using R2DBC

Metrics and observability improvements

This release brings in many welcome metrics and observability improvements.

  • Metric names exposed by the Spring Boot metric actuator (/actuator/metrics/) are now alphabetically ordered. Nice!
  • Spring Boot is using Micrometer 1.5 (LTS release)
  • Kafka consumer metrics are already exposed in previous versions of Spring Boot. Now also Kafka producer metrics are exposed by Micrometer out of the box.
  • Improved support for Wavefront (VMware Tanzu Observability)

Tanzu Observability by Wavefront is a SaaS-based metrics monitoring, and analytics platform that lets (Spring Boot) developers visualize, query, and alert over data from across your entire stack. Including infrastructure, network, custom app metrics, business KPIs, etc. Based on metrics, traces
and span logs.

Add the Spring Cloud Sleuth starter:

or OpenTracing starter dependency to send trace data to Wavefront.

When the Spring Boot application starter starts up, it negotiates a token for your application with Wavefront. Your dashboard is already ready and waiting for you by the time the application starts up.

To share this account, make sure the following is added to your configuration:

management.metrics.export.wavefront.api-token=api-token-generated-by-wavefront
management.metrics.export.wavefront.uri=https://wavefront.surf

Connect to your Wavefront dashboard using this one-time use link:
https://wavefront.surf/us/kpjHGQ5n0D

Now copy the generated API token in your Spring Boot configuration application.yml and start the application:

Open the one time link to see your Wavefront Dashboard.

Be aware the current version of the Spring Boot Wavefront dependencies that ships with Spring Boot 2.3 is still a release candidate (2.0.0-RC1)!

Source: VMWare Tanzu Wavefront — Spring Boot Petclinic example
  • The auto-configuration for Wavefront has been updated to define a WavefrontSender bean.
  • Both metrics and traces are now sent to Wavefront over a single connection.

Validation starter not included in web starters anymore!

The spring-boot-starter-validation is not a transitive dependency of spring-boot-starter-web and spring-boot-starter-webflux anymore. If you are using validation features:

make sure to add the validation starter to your project yourself!

Dependency upgrades

Spring Boot 2.3 ships with many dependency upgrades.

Spring related dependency upgrades:

  • Spring Data Neumann-RELEASE
  • Spring HATEOAS 1.1.0.RELEASE
  • Spring Integration 5.3.0.RELEASE
  • Spring Kafka 2.5.0.RELEASE
  • Spring Security 5.3.2.RELEASE
  • Spring Session Dragonfruit-RELEASE

Most important third-party dependencies upgrades:

  • Artemis 2.12
  • Cassandra driver 4.6.1 (breaking changes)
  • Couchebase client 3.0.4 (breaking changes)
  • Elasticsearch 7.6.2
  • Flyway 6.4.1
  • Hibernate Validator 6.1
  • Infinispan 10.1
  • Jackson 2.11.0
  • Kafka 2.5.0
  • Kotlin 1.3.72
  • Lombok 1.18.12
  • Log4j 2.13.2
  • MongoDB 4.0.3
  • Micrometer 1.5.1
  • Solr 8.5.1
  • QueryDSL 4.3.1

Testing dependencies

  • AssertJ 3.16
  • JUnit Jupiter 5.6
  • Mockito 3.3

Java 14 Support

Next to Java 8 and 11, Spring Boot 2.3 now also supports Java 14.

What has been removed from Spring Boot?

Most deprecated classes, methods, and properties that were deprecated in Spring Boot 2.2 are removed in Spring Boot 2.3.

  • Support for the native Elasticsearch transport client library and Jest (a Java HTTP Rest client for Elasticsearch) library in favor of the official HTTP client provided by Elastic.
  • Spring Cloud Connectors starter in favor of Java CFEnv. Java CFEnv is a library for easily accessing the environment variables set when deploying a (Java) application to Cloud Foundry.
  • Spring Boot’s build no longer makes use of the Maven exec-maven-plugin and plugin management, for it has been removed. If you were relying on Spring Boot’s managed version, you should add your own plugin management.

Deprecations

For a complete overview of all the deprecations in Spring Boot 2.3, see the release notes.

Migration to Spring Boot 2.3

Be aware most classes, methods, and properties that deprecated in Spring Boot 2.2 are removed in Spring Boot 2.3. Verify you aren’t calling deprecated methods before upgrading.

Also, take a look at the spring-boot-properties-migrator module, it helps you to spot properties that have been deprecated or renamed. Next to printing those properties at startup, the module also takes care of temporarily migrate properties at runtime for you. That’s awesome 😎. But don’t be lazy, change the properties accordingly!

Properties migrator in action:

The list of deprecations in Spring Boot 2.2 might be helpful as well.

For more information, check the:

Other interesting blog posts related to Spring Boot 2.3

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.