Spring 5.0 is the first major release since Spring 4 was released in 2013, and 5.0 M1 was released on July 28, 2016. So what are the new features of Spring 5? Let’s take a look

Basically, it can be classified as follows:

  • JDK Version Upgrade
  • Core framework revised, Core container updated
  • Kotlin functional programming
  • Responsive programming model
  • Testing improvement
  • Additional library support
  • Stop maintaining some features
JDK Version Upgrade

The code for Spring 5 is based on the Java 8 syntax specification, so to use Spring 5, you need a JDK version 8.0 or older. Spring 5.0 originally wanted to use Java 9, but Java 9 was released 18 months later than Spring, and the Spring development team decided to remove the Java 9 dependency from Spring 5.0.

Core Framework Revision

Based on Java8 reflection enhancements, method parameters can be accessed efficiently in Spring5

The core Spring interface provides optional declarations using Java 8’s default interface implementation, the default method

@nullable and @notnull annotations mark method arguments and return values exactly. This allows you to handle null values at compile time without throwing NullPointerExceptions at run time.

On the Logging side, Spring 5.0 provides a Common Logging bridge module, Spring-JCL, that replaces standard Common Logging and automatically detects log4j2.x,SLF4J,JUL(java.util.logging), No additional dependency is required.

Kotlin functional programming

Spring 5.0 introduces JetBrains support for Kotlin, an object-oriented programming language that supports functional programming. Kotlin also runs on the JVM, and with Kotlin’s support, developers can use Spring’s functional programming to handle Web entry points and Bean registration.

For example, you could write the following code style.

At the entry point of the Web:

{("/movie" and accept(TEXT_HTML)).nest {
GET("/", movieHandler::findAllView)
GET("/{card}", movieHandler::findOneView)
}
("/api/movie" and accept(APPLICATION_JSON)).nest {
GET("/", movieApiHandler::findAll)
GET("/{id}", movieApiHandler::findOne)
}
}
Copy the code

When registering a Bean:

val context = GenericApplicationContext {
registerBean()
registerBean { Cinema(it.getBean()) }
}
Copy the code
Responsive programming model

The exciting Spring 5.0 feature is its responsive Web programming

Reactive Streams is a specification developed by NetFlix, Pivotal, Typesafe, Red Hat, Oracle, Twitter, and Sprash.io. It provides some generic apis that you can control when implemented, just like Hibernate’s JPA, where JPA is the API and Hibernate is the implementation.

Reactive flows are an official module in Java9, but in Java8 we need to introduce additional dependencies. Spring5.0 streaming supports the Project Reactor API based on responsive streaming

Spring 5.0 has a new module called Spring-WebFlux that supports responsive Http and WebSocket clients.

With Spring Webflux, you can create Webclient, which is a reactive and non-blocking alternative to RestTemplate. Here is a code example:

WebClient webClient = WebClient.create();
Mono person = webClient.get()
.uri("http://localhost:8080/movie/42")
.accept(MediaType.APPLICATION_JSON)
.exchange()
.then(response -> response.bodyToMono(Movie.class));
Copy the code
Testing improvement

Spring 5.0 fully supports Junit 5, and tests can be executed in parallel within the TestContext framework. For responsive programming, Spring-test provides WebTestClient to test Spring-WebFlux. WebTestClient, like a server MockMvc doesn’t need to run.

Of course, Spring 5.0 still supports Junit 4, which will be around for some time to come.

Additional library support

Spring 5.0 now supports the following library versions:

  • JackSon 2.6 +
  • EhCache 2.10+ / 3.0 GA
  • Hibernate 5.0 +
  • JDBC 4.0 +
  • XmlUnit 2.x+
  • OkHttp 3.x+
  • Netty 4.1 +
Some features to stop maintenance

At the Api level, Spring5.0 no longer supports the following packages:

  • beans.factory.access
  • jdbc.support.nativejdbc
  • Mock. Staticmock for the Spring-Aspects module
  • Web.view.tiles2m. Tiles 3 is now the minimum required version
  • The orm. Hibernate3 and orm. Hibernate4. Hibernate5 is now supported

The following libraries are no longer supported:

  • Portlet
  • Velocity
  • JasperReports
  • XMLBeans
  • JDO
  • Guava

If you are using any of the libraries mentioned above in your current project, it is best not to upgrade to Spring5

summary

Responsive programming is becoming more and more popular, and we will see more and more technologies implementing responsive solutions, so those interested in responsive programming can learn more.

reference

  • What’s new in Spring Framework 5?