Recently Andy Wilkinson (@ankinson) from the Spring Boot core team announced the release of Spring Boot 2.1. During the last days, I played around with the new version and will present you the most important updates from my point of view.
Spring Boot 2.1.0 has been released: https://t.co/01acMWbF0P. There's lots of good stuff in this one, including support for Java 11. Thank you to everyone who has contributed to the project. There are over 500 of you now!
— Andy Wilkinson (@ankinson) October 30, 2018
Support for Java 11
I think the most important update for this new release is the support of Java 11 which was released in September this year and is the latest LTS version of Java. Trying the new features of Java 9, 10 and 11 with just plain Java SE is nice, but without the support of your framework, you can't utilize the features in production. To my knowledge Spring is also the first major Java framework that supports Java 11 and was able to release a production-ready version about one month after Java 11 GA. Bootstrapping a new Spring Boot project with Java 11 will result in the following pom.xml
and will out of the box with no additional configuration.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>de.rieckpil.blog</groupId> <artifactId>whats-new-in-spring-boot-2.1</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>whats-new-in-spring-boot-2.1</name> <description>Updates to Spring Boot 2.1</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.0.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>11</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> |
Third-party library upgrades
Spring Boot 2.1 upgrades to the core Spring Framework with version 5.1 which comes with initial refinements for GraalVM, functional bean definitions for Java and Kotlin, improved startup time and less heap memory consumption due to optimizing the internal use of reflection.
Other notable upgrades are the following:
- Tomcat 9 (now implements Servlet 4.0 spec): Release Notes
- Undertow 2 (now implements Servlet 4.0 spec and HTTP/2 ready): Release Notes
- Hibernate 5.3 (now JPA 2.2 ready and JDK 11 support): Release Notes
- JUnit 5.2: Release Notes
Other news
Logging Groups
We are now able to group different packages for which we want to define a common log level in a so-called logging group. With this you can group e.g. all your business logic related classes into a group and define DEBUG as the log level and TRACE for example for your messaging interfaces which will log all the incoming messages:
1 2 3 4 5 | # define the group logging.group.corelogic=de.rieckpil.blog.payments, de.rieckpil.blog.transfers ... # use the group (possibly in a different configuration file) logging.level.corelogic=DEBUG |
There are also to pre-defined logging groups web
and sql
which are provided out-of-the-box.
Bootstrap mode for JPA setup
Bootstrapping a Spring Boot application with a lot of JPA entities and JPA repositories from Spring Data can influence the startup time of your application. With the Spring Data Lovelace release, they introduced a so-called bootstrap mode where you can define the initialization of the repositories. In the default mode, the full initialization happens during the startup of the application. The deferred
mode uses a background JPA infrastructure initialization deferred until the ApplicationContext
has completed its initialization. With lazy
you get the JPA infrastructure initialization deferred until the first access:
1 | spring.data.jpa.repositories.bootstrap-mode=lazy |
For a sample project to show the differences, have a look at the following repository: Spring Data JPA – Deferred bootstrap modes
JUnit 5 improvements
With Spring Boot 2.1 you can remove the required @ExtendWith(SpringExtension.class)
annotation if you are using a Spring Boot testing annotation @…
like @DataJpaTest
as they are all now meta-annotated with the Spring extension. In addition, you now don't have to do any custom setup for your Maven plugins to make use of JUnit 5.
1 2 3 4 5 6 7 8 9 10 | @SpringBootTest // no @ExtendWith(SpringExtension.class) needed public class ApplicationTests { @Test @DisplayName("Load the whole Spring context") public void contextLoads() { } } |
There are a lot more upgrades and news but these were one of the most useful ones for my projects. You find the full list of news in the official Release Notes on GitHub.
A sample Spring Boot 2.1 project with Java 11 can be found in my GitHub repository.
See you,
Phil