Spring Boot 2 – An overview: All those “little” updates and improvements
Upgrades to the latest version of supported libraries and tools, enhancements through and with Spring Framework 5, and changes to the heart of Spring Boot. The second major release of Spring Boot leaves no stone unturned. The last part of this series focuses on some “minor” changes and improvements in Spring Boot 2.
Michael Simons is a speaker at JAX 2018 and author of the book “Spring Boot – Moderne Softwareentwicklung im Spring Ökosystem“, published by dpunkt.verlag.
Java 8 baseline and Java 9+ support
Spring Boot 2 is based on the Spring Framework 5 and therefore requires Java 8. Conversely, this signifies that Spring Boot 2 cannot run on Java 7 or older versions of the programming language. Spring Framework 5 is fully compatible with Java Development Kit 9 (JDK 9), both in development and deployment, and works on both the class and module paths.
But what about Jakarta EE / Java EE?
Spring Framework 5 requires the Java EE 7 API and supports the Java EE 8 API at runtime. This means that at least Tomcat 8.5, Jetty 9.4 or WildFly 10 are required. Servlet 4, Validation 2.0, JPA 2.2 and JSON Binding 1.0 are also supported and have been tested extensively.
Spring Framework 5
Upgrading to Spring Framework 5 removes several deprecated classes and features including Hibernate 3 and 5, Tiles 3, Portlet, Velocity, JasperReports, XMLBeans, JDO and Guava in particular. If your application relies on one or more of these features, better stick to the Spring Boot 1.5.x release cycle. Furthermore, Spring Framework 5 brings new features: interfaces are consistently annotated with
NotNullable and the core container supports functional bean registration (the 4th possibility to build components according to XML, annotations and the explicit Java configuration).
Updated Web MVC and a completely revamped WebFlux
I already presented the new WebFlux module in detail, but the Web MVC was also updated: It supports the Servlet 4.0 specification, is now independent of the Java Activation Framework, can bind immutable objects and much more.
Spring Framework 5 has first-class support for Kotlin based on a domain-specific language (DSL). It is used to configure the application context, to route WebFlux and for a multitude of adaptations regarding language features. These features include reified types to avoid constant casting.
While Spring Boot 2 still uses JUnit 4 for testing by default, it fully supports the JUnit Jupiter platform via Spring Framework 5 and provides
@SpringJUnitConfig and more. Plus: If you want to annoy your colleagues, you may make use of
@DisabledIf on the CI server.
Further notable updates
Major updates of the following dependencies have also been applied:
- Thymeleaf 3 is now not only supported, but default. This can result in some work if your application uses its own dialects.
- Flyway is now used in version 5.
- The update to Hibernate 5.2 will force you to take another look at your entity mapping code.
Changes in Spring Boot 2
@ConfigurationPropertiesare only validated if they are marked as
- The binding mechanism has been completely rewritten and can be used in a trivial way if you want to test and bind properties very early as part of a starter.
- All properties, packages and classes used in the context of an embedded servlet container have been restructured and now reflect the dualism of Spring Web MVC and WebFlux.
- There is a practical new starter:
spring-boot-starter-json. This will load and register all libraries Json needs to process Java-8 data types.
- Spring Boot now uses HikariCP as the default pool for database connections.
- If Hibernate is used in combination with an embedded database,
spring.jpa.hibernate.ddl-autois only set to
create-dropif no schema manager like Flyway or Liquibase is involved.
- Custom starters are affected by a small but important change:
ORto link multiple, specified beans.
A Hello World application will easily be migrated. In most cases, however, applications in the real world consist of more than one endpoint. The numerous upgrades of upstream libraries alone should be treated with caution.
There is nothing wrong with setting up new services using Spring Boot 2. It has now been in development for over a year and as the author of a book on the subject, it was an interesting experience to accompany this development. However, an existing application should not be updated simply by changing a version number in the build file.
— Brian Clozel (@bclozel) 5. Dezember 2017
As a reward for upgrading, there are reactive applications, modern platforms and last but not least: animated banners (see Tweet). So now I know which topic I can take up as an example for my own starters in 2018.
The Spring Boot book will be published in late April 2018 and will cover all current topics related to Spring Boot 2. In addition to the reactive programming model with Spring 5, this includes the new actuator infrastructure, Micrometer.io support and much more. This book is intended to appeal to interested developers from the Java EE area as well as Spring developers and give them a “recipe” to handle recurring tasks from everyday business life elegantly and without distraction using Spring Boot.