Spring Boot 2.0 New Features: Infrastructure Changes

February 13, 2018 · 5 min read – Last updated on October 26, 2019

In my previous post, Spring Boot 2.0 New Features: The 3 Most Important Changes You Must Know About, I pointed out the one of the notable changes coming with Spring Boot 2 will be infrastructure updates. This post enumerates these updates so that you can see their impact once before you would upgrade.

1. Spring Boot 2 baseline changes

1.1. Java 8 Baseline

Releasing a new major version gave the Spring team the opportunity to rebase the codebase upon Java 8 and use its new features. Therefore Spring Boot 2.0 requires Java 8 or later, consequently it doesn’t support Java 6 and Java 7 any more, because they reached their end of life anyway.

1.2. Java 9 Support

Spring Boot 2 fully supports it and there is a dedicated page Spring Boot with Java 9 that provides more details if you want to run Spring Boot apps with Java 9.

1.3. Spring Framework 5.0

Spring Boot 2.0 builds on and requires Spring Framework 5.0. Altought Spring 5 has been generally available since September of 2017, probably most projects will start to adapt it when Spring Boot 2.0 hits GA. Spring 5 introduces a number of nice refinements as well and one of the most noteworthy of its new features is its extensive support for building reactive applications in a next post.

2. Embedded Servlet Containers

Tomcat Jetty Undertow

2.1. Jetty

The minimum supported version of Jetty is 9.4.

2.2. Tomcat

The minimum supported version of Tomcat is 8.5

2.3. TLS configuration

You can configure SSL for your WebFlux application with server.ssl.* configuration properties and all available servers (Tomcat, Jetty, Undertow and Reactor Netty) supports this configuration.

2.4. HTTP/2 support

Spring Boot also enables your MVC or WebFlux applications to use HTTP/2 by setting server.http2.enabled. It’s supported for Tomcat, Undertow and Jetty. Depending on your choice of server and JDK, restrictions and prerequisites can apply.

3. Build

Maven Gradle

3.1. Maven

Maven projects are compiled with the -parameters compiler flag by default.

3.2. Gradle

Spring Boot requires Gradle 4.x. Spring Boot’s Gradle plugin has been largely rewritten to enable a number of significant improvements. You can read more about the plugin’s capabilities in its reference and api documentation.

3.2.1. Configuring Gradle bootRun

The BootRun task provides properties for configuring the application’s arguments (args) and JVM arguments (jvmArgs) and more advanced configuration is available via execSpec. See the Gradle plugin’s documentation for more details. Based on user feedback, the BootRun task is once again a subclass of Gradle’s JavaExec task. It can be configured in the same way as any other JavaExec task.

4. JDBC / ORM changes

Hibernate Jooq Flyway Liquibase

4.1. Default connection pool

The default connection pool has changed from Tomcat to HikariCP. If you are using Hikari in an environment where tomcat-jdbc is provided, you can remove the spring.datasource.typeoverride. Similarly, if you want to stay with the Tomcat connection pool, simply add the following to your configuration:

spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource

4.2. Database Migration

Liquibase and Flyway configuration keys were moved to the spring namespace (i.e. spring.liquibase and spring.flyway respectively).

4.2.1. Flyway/Liquibase flexible configuration

If only a custom url or user is provided, the auto-configuration reuses the standard datasource properties rather than ignoring them. This allows you to create a custom DataSource for the purpose of the migration with only the required information.

4.2.2. Detection of DataSource initialization

If Flyway or Liquibase is managing the schema of your DataSource and you’re using an embedded database, Spring Boot 2 will automatically switch off Hibernate’s automatic DDL feature.

4.3. Database initializer

Database initialization for Spring Batch, Spring Integration, Spring Session and Quartz occurs by default only when using and embedded database. The enabled property has been replaced with a more expressive enum. For example, if you want to always perform Spring Batch initialization you can set spring.batch.initialize-schema=always.

4.4. DataSource Initialization

DataSource initialization is only enabled for embedded data sources and will switch off as soon as you’re using a production database. Furthermore the new spring.datasource.initialization-mode(replacing spring.datasource.initialize) offers more control.

4.5. Data Sources Metrics

Instrumentation takes care of monitoring all available data sources and publishes metrics (min, max and usage) metrics for each.

4.6. Configurable JPA mapping resources

If you were extending Spring Boot’s JPA configuration to register mapping resources, there is a spring.jpa.mapping-resources property.

4.7. JdbcTemplate

The JdbcTemplate that Spring Boot auto-configures can be customized via the spring.jdbc.template namespace. Also, the NamedParameterJdbcTemplate that is auto-configured reuses the JdbcTemplate behind the scenes.

4.8. jOOQ

Spring Boot detects the jOOQ dialect automatically based on the DataSource (similarly to what is done for the JPA dialect). Also a @JooqTest has been introduced to ease testing where only jOOQ has to be used.

4.8. Hibernate

The minimum supported version of Hibernate is 5.2. Read Hibernate 5.2 Migration Guide to find out how to upgrade.

4.8.1. Support for custom Hibernate naming strategies

For advanced scenario, you can define the ImplicitNamingStrategy or PhysicalNamingStrategy to use as regular beans in the context.

4.8.2. Hibernate properties customization

It is possible to customize the properties Hibernate uses in a more fine grained way by exposing a HibernatePropertiesCustomizer bean.

5. NoSQL

Cassandra Couchbase Redis MongoDB InfluxDB

5.1. Cassandra

The spring.data.cassandra exposes pooling options.

5.2. Reactive Couchbase support

Support for Spring Data reactive repositories is available for Couchbase and a spring-boot-starter-data-couchbase-reactive is available to easily get started.

5.3. InfluxDB

If the InfluxDB java client and the spring.influx.url is set, an InfluxDB client is automatically configured. Support for credentials is available as well. The health endpoint can monitor an InfluxDB server.

5.4. Redis cache configuration

It is possible to expose a RedisCacheConfiguration to take control over the RedisCacheManager. A new annotation @DataRedisTesthas also been introduced.

5.5. Elasticsearch

Spring Boot 2 requires Elasticsearch 5.4 from now on. In line with Elastic’s announcement that embedded Elasticsearch is no longer supported, auto-configuration of a NodeClient has been removed. A TransportClient can be auto-configured by using spring.data.elasticsearch.cluster-nodesto provide the addresses of one or more nodes to connect to.

5.6. MongoDB

It is possible to apply advanced customizations to the MongoDB client that Spring Boot auto-configures by defining a bean of type MongoClientSettingsBuilderCustomizer.

6. Testing

6.1. Mockito 1.x

Mockito 1.x is no longer supported for @MockBean and @SpyBean. If you don’t use spring-boot-starter-test to manage your dependencies you should upgrade to Mockito 2.x.

6.2. Kotlin extensions for TestRestTemplate

The Kotlin RestTemplate extensions are also available for TestRestTemplate to make the developer experience consistent.

6.3. Testing improvements

Converter and GenericConverter beans are automatically scanned with @WebMvcTest and @WebFluxTest.

Reference: Spring Boot 2.0 Release Notes.