春 5

2017年末にSpring 5がリリースされました。Spring 5にはSpringフレームワークの大幅なアップデートがあります。Spring 4は2013年にリリースされたため、フレームワークの大改修が期待されていました。新たなSpringフレームワークの新機能を見ることができて、とても嬉しいです。

「Spring 5の特徴」

Spring 5の機能は、大きく以下のカテゴリに分けることができます。

  • Java Baseline Support
  • Core API Enhancements
  • Spring Web MVC Enhancements
  • Spring WebFlux
  • Functional Programming with Kotlin Support
  • Testing Improvements
  • Deprecated Support and Removed Packages

Javaのベースラインサポート

  • Spring 5 runs on Java 8, so spring code can leverage lambda expressions to improve code readability.
  • Spring 5 also supports java 9, so we can create our applications on module based architecture too.
  • Spring 5 supports Java EE 7 and also compatible with Java EE 8. So we can use Servlet 4.0, Bean Validation 2.0, JPA 2.2 in our applications. We can also use their older versions i.e. Servlet 3.1, Bean Validation 1.1, JPA 2.1.
  • Spring 5 applications preferred server versions are Tomcat 8.5+, Jetty 9.4+ and WildFly 10+.

私は、Spring 5が様々な最新バージョンのテクノロジーに追いつこうとしていることが本当に好きです。

コアAPIの強化

  • Non-null API declaration at the package level. Nullable arguments, fields and return values are explicitly annotated with @Nullable annotation.
  • File operations are performed via NIO 2 streams i.e. no FileInput/Output Stream. This is a great enhancement and performance boost for file based applications.
  • Spring Framework 5.0 comes with its own Commons Logging bridge; spring-jcl instead of standard Commons Logging.
  • Support for providing spring components information through index file “META-INF/spring.components” rather than classpath scanning. This will improve startup time a lot if you have a large spring project and many spring components. It will be better for developers too, because we can directly look into specified files to figure out the application entry point rather than searching through the entire classpath files.

Spring Web MVCの強化

Spring MVCモジュールは、最新のJava EEテクノロジーを使用することによって大幅に改良されました。主な改善点は以下の通りです。

  • Full Servlet 3.1 signature support in Spring-provided Filter implementations.
  • Support for Servlet 4.0 PushBuilder argument in Spring MVC controller methods.
  • MaxUploadSizeExceededException for Servlet 3.0 multipart parsing on common servers.
  • Unified support for common media types through MediaTypeFactory delegate.
  • Data binding with immutable objects using Kotlin, Lombok, @ConstructorProperties.
  • Support for the JSON Binding API as an alternative to Jackson and GSON.
  • Support for Reactor 3.1 Flux and Mono as well as RxJava 1.3 and 2.1 as return values from Spring MVC controller methods.
  • Support for ResponseStatusException as a programmatic alternative to @ResponseStatus.

春のWebFlux

Spring WebFluxは新しいモジュールであり、spring-webmvcモジュールの代替です。また、リアクティブフレームワークをベースに構築されています。このモジュールは、イベントループの実行モデルに基づいて、完全非同期かつノンブロッキングなアプリケーションを作成するために使用されます。

  • Reactive infrastructure in spring-core such as Encoder and Decoder for encoding and decoding streams of Objects.
  • @Controller style, annotation-based, programming model, similar to Spring MVC, but supported in WebFlux, running on a reactive stack.
  • New WebClient with a functional and reactive API for HTTP calls, comparable to the RestTemplate but through a fluent API and also excelling in non-blocking and streaming scenarios based on WebFlux infrastructure.

Kotlinサポートを備えた関数型プログラミング

Spring 5では、今やKotlinプログラミングもサポートされています。これは、Javaが関数型プログラミングに向かって進んでいるように、関数型プログラミングをサポートすることへの大きな進歩です。

  • Support for Null-Safe API
  • Support for Kotlin immutable classes with optional parameters and default values.
  • Leveraging Kotlin reified type parameters to avoid specifying explicitly the Class to use for serialization/deserialization in various APIs like RestTemplate or WebFlux APIs.
  • Support for Kotlin autowired constructor with optional parameters.
  • Kotlin null-safety support for @Autowired/@Inject and @RequestParam/@RequestHeader/etc annotations.

改善のテスト

  • Support for JUnit 5
  • Support for parallel test execution in the Spring TestContext Framework

非推奨サポートおよび削除されたパッケージ

  • Removed packages beans.factory.access, jdbc.support.nativejdbc, mock.staticmock from spring-aspects module.
  • Removed packages web.view.tiles2 and orm.hibernate3/hibernate4 dropped. This means if you are planning to use Spring 5, you will also have to use Hibernate 5.
  • Dropped support for old technologies Portlet, Velocity, JasperReports, XMLBeans, JDO, Guava. If you are using any of these, then either migrate to some other technologies or stay with Spring 4.

Spring 5の機能についての簡単な概要は以上です。参考: Spring GitHubドキュメント。

コメントを残す 0

Your email address will not be published. Required fields are marked *