Spring Boot 2.0 is just around the corner, but what is actually new in Spring Boot 2.0? As expected, it comes with new features and improvements, and in this article, I will try to summarize the key parts of the release.



New in Spring Boot 2.0

Java 9 support

New in Spring Boot 2 is that Java 9 is officially supported, which is something that I’ve looked forward to a lot personally. The minimum required JDK is now Java 8, which means that you can not run Spring Boot 2.0.0 with JDK 7 or older.

Spring Framework

Spring Framework 5.0 now comes packaged with Spring Boot. A couple of interesting features in Spring Framework 5.0 includes:

Adds support for @Nullable and @NotNull annotations to deal with NullPointerExceptions at compile time rather than runtime.

to deal with NullPointerExceptions at compile time rather than runtime. Detection of Log4j2.x, SLF4J, and java.util.logging without any extra dependencies.

any extra dependencies. Decreased startup time for larger project while using candidate component index instead of classpath scanning. On smaller projects you might not notice much difference but on larger projects you will as the number of classes increases, the startup time remains constant. See Spring’s Jira for more information.

project while using component index instead of classpath scanning. On smaller you might not notice much difference but on larger you will as the number of classes increases, the startup time remains constant. See Spring’s Jira for more information. Support for JetBrains new and popular Kotlin language. Kotlin is an object-oriented language with a lot of support for functional programming. It is fully interoperable with Java meaning that you can write Kotlin classes and code that you use in the Java part of your code and vice versa.

The new reactive stack web framework is now available in Spring. See Reactive Java for more details what it is. A WebClient implementation of a REST endpoint using the reactive stack web framework could look like this. Mono<Movie> movie = webClient.get() .uri("http://localhost:8080/movie/42") .accept(MediaType.APPLICATION_JSON).exchange() .then(response -> response.bodyToMono(Movie.class));

of a REST endpoint using the reactive stack web framework could look like this. JUnit 5 Jupiter is now fully supported in Spring Framework 5.0, making it possible to write tests in JUnit 5. Spring Framework 5.0 also makes it possible to run parallel tests in Spring TestContext framework. There is also a new test client called WebTestClient , which similar as MockMvc does not require running the server. Instead it relies on mocking the requests and responses. The WebTestClient can bind to the infrastructure of WebFlux.

Spring Security

Not officially part of Spring Boot, but still worth to mention as it plays nicely with Spring Framework 5.0. Spring Security version was updated to 5.0 and comes with over 400+ enhancements and bug fixes. The highlights of the release are the following new features.

Makes it possible for users to authenticate by using their existing accounts at an OAuth 2.0 provider. For example, GitHub, Google or Facebook. See Spring Security documentation for further details, and instructions on how to set it up.

Similar to Spring Framework, the new Spring Security release is adding Reactive support so that you can secure your reactive application in a convenient way. See @EnableWebFluxSecurity, @EnableReactiveMethodSecurity and WebFlux Testing Support.

Password Encoding done in a more modern way. Password encoding is something that changes frequently as we often have found better practices for storing passwords in the safest way. Introduces DelegatingPasswordEncoder that tries to solve a couple of problems with staying up-to-date with current best practices in password encoding.

@ConditionalOnBean

Important to consider when migrating from Spring Boot 1.x to 2.x is that the annotation @ConditionalOnBean annotation now uses logical AND instead of logical OR for combining conditions.

Updates of minimum supported versions

Jetty 9.4

Tomcat 8.5

Hibernate 5.2

Gradle 3.4

Thymeleaf

Also new in Spring boot 2.0 is that Thymeleaf 3 is now officially supported which is an update to both Thymeleaf and Spring Security Thymeleaf dependencies. Some noticeable changes in Thymeleaf 3 are listed below.

It is recommended to remove th:inline=”text” attributes as they no longer are required. You can keep them if you want for readability purposes, however, removing them will slightly benefit you with some extra processing performance.

Thymeleaf is no longer XML-based because of a new parsing system, so there is no need for you to write XML-valid HTML code. Even though, of course, it is still recommended to do so. But at least now Thymeleaf will be more forgiving if you forgot to close tags or missed quoting attributes, and etc.

There is a new textual template mode which grants Thymeleaf the ability to output CSS, Javascript, and plain text. For Thymeleaf to have all this feature available for all the textual modes, a new syntax has been introduced. An example is displayed below for iterating a list. [# th:each="item : ${items}"] - [# th:utext="${item}" /] [/]

Performance improvements. It might be a bit obvious that with a new release there is some sort of performance improvements but the main achievement of version 3.0 is actually a very significant improvement in performance. The enginge was rewritten from scratch with performance in mind.

And of course a lot more, see Thymeleaf 3 migration guide.

Final words

Spring Boot 2.0 is a released packed with great stuff. I believe the main arguments for upgrading are:

Java 9 support

Better support for reactive applications

Thymeleaf 3 support

If you benefit from any of this three things, then you should definitely consider upgrading. And also, do not forget, that the release also includes a lot of bug fixes and performance improvements which alone makes a strong case for upgrading.

Like this: Like Loading...