Spring Boot 2.0 New Features: Infrastructure Changes
Spring Boot 2.0 New Features: Infrastructure Changes
Spring Boot's back and it's better than ever! Let's fly over some of the recent changes to Spring Boot 2.0 to see what infrastructure changes have been made.
Join the DZone community and get the full member experience.Join For Free
FlexNet Code Aware, a free scan tool for developers. Scan Java, NuGet, and NPM packages for open source security and open source license compliance issues.
In my previous post, Spring Boot 2.0 New Features: The 3 Most Important Changes You Must Know About, I pointed out 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.
Spring Boot 2 Baseline Changes
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 anymore, because they reached their end of life anyway.
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.
Spring Framework 5.0
Spring Boot 2.0 builds on and requires Spring Framework 5.0. Although Spring 5 has been generally available since September of 2017, most projects will probably start to adopt 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.
Embedded Servlet Containers
The minimum supported version of Jetty is 9.4.
The minimum supported version of Tomcat is 8.5
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.
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.
Maven projects are compiled with the
-parameters compiler flag by default.
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.
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
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.type override. Similarly, if you want to stay with the Tomcat connection pool, simply add the following to your configuration:
Liquibase and Flyway configuration keys were moved to the
spring namespace (i.e.
Flyway/Liquibase Flexible Configuration
If only a custom
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.
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.
Database initialization for Spring Batch, Spring Integration, Spring Session, and Quartz occurs by default only when using an 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
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.initialize) offers more control.
Data Sources Metrics
Instrumentation takes care of monitoring all available data sources and publishes metrics (min, max, and usage) metrics for each.
Configurable JPA Mapping Resources
If you were extending Spring Boot’s JPA configuration to register mapping resources, there is a
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.
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.
The minimum supported version of Hibernate is 5.2. Read Hibernate 5.2 Migration Guide to find out how to upgrade.
Support for Custom Hibernate Naming Strategies
For advanced scenario, you can define the
PhysicalNamingStrategy to use as regular beans in the context.
Hibernate Properties Customization
It is possible to customize the
properties Hibernate uses in a more fine-grained way by exposing a
spring.data.cassandra exposes pooling options.
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.
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
Redis Cache Configuration
It is possible to expose a
RedisCacheConfiguration to take control over the
RedisCacheManager. A new annotation
@DataRedisTesthas also been introduced.
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.
Mongo Client Customizations
It is possible to apply advanced customizations to the MongoDB client that Spring Boot auto-configures by defining a bean of type
Mockito 1.x is no longer supported for
@SpyBean. If you don’t use
spring-boot-starter-test to manage your dependencies you should upgrade to Mockito 2.x.
Kotlin Extensions for
RestTemplate extensions are also available for
TestRestTemplate to make the developer experience consistent.
GenericConverter beans are automatically scanned with
Published at DZone with permission of Laszlo Csontos , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.