Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Spring Framework 5.0: Themes & Trends

Spring Framework 5.0: Themes & Trends

Spring Framework 5.0, scheduled for release in early 2017, focuses on several key themes: in particular reactive web applications based on Reactive Streams, with a traditional server or with an embedded runtime, as well as comprehensive support for JDK 9. This talk presents the current state of development in the middle of the milestone phase and gives a concrete outlook on the remaining roadmap.

Juergen Hoeller

October 15, 2016
Tweet

More Decks by Juergen Hoeller

Other Decks in Programming

Transcript

  1. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 1 Spring Framework 5.0 Themes & Trends a.k.a. Reactive Microservices on JDK 9 Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Juergen Hoeller Spring Framework Lead Pivotal
  2. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 2 Spring Framework 4.3 ▪ Last 4.x feature release! ▪ 4.3 GA: June 2016 ▪ Extended support life until 2019 • on JDK 6, 7, 8 • on Tomcat 6, 7, 8.0, 8.5 • on WebSphere 7, 8.0, 8.5 and 9 ▪ Programming model refinements brought forward to JDK 6+ • DI & MVC refinements • composed annotations
  3. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 3 Spring Framework 5.0 ▪ A new framework generation for 2017+ ▪ 5.0 M1: July 2016 ▪ 5.0 GA: planned for March 2017 ▪ Major baseline upgrade • JDK 8+, Servlet 3.0+, JMS 2.0+, JPA 2.1+, JUnit 5 ▪ Key infrastructure themes • JDK 9 and Jigsaw modules • Servlet 4.0 and HTTP/2 • Reactive architectures
  4. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 4 Core Container Overhaul ▪ Largely in 4.3.x already... • completing the annotation-based component model • composable annotations across the framework • efficient caching of internal data structures ▪ Exclusively in 5.0... • default methods & use of Java 8 types in core interfaces (M1) • component index for efficient component-scan resolution (M2) • flexible programmatic bean registration & resolution (M3)
  5. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 5 JDK 9 HTTP/2 Reactive
  6. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 6 Comprehensive JDK 9 Support ▪ Spring 5 schedule is close to JDK 9 schedule • JDK 9 intends to go GA in July 2017 (after two delays already) ▪ Jigsaw – a new module system for applications • symbolic module names and requires/exports metadata for jar files • currently no versioning, just structuring plus visibility enforcement • module path as alternative to class path ▪ New HTTP client and general support for HTTP/2 • superseding the outdated java.net.HttpURLConnection • TLS extension for ALPN
  7. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 7 Using Jigsaw with Spring ▪ Spring Framework jars as Jigsaw-compliant modules out of the box • internally declaring module-info for each jar • or as “automatic modules” (for the time being) ▪ Separate module namespace, following Maven Central jar naming • spring-context, spring-jdbc, spring-webmvc ▪ An application's module-info.java can then look as follows... module my.app.db { requires spring.jdbc; }
  8. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 8 JDK 9 HTTP/2 Reactive
  9. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 9 The Importance of HTTP/2 (RFC 7540) ▪ Enormous benefits over HTTP 1.1 (which dates back to 1996) • binary protocol • TLS (SSL) everywhere • connection multiplexing • headers compression • request prioritization • push of correlated resources ▪ Browsers already implement HTTP/2 over TLS • major websites work with HTTP/2 already: Google, Twitter, etc • We need to embrace it in Java land as well!
  10. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 10 Spring 5 and HTTP/2 ▪ Servlet 4.0 – September 2017 • enforces support for HTTP/2 in Servlet containers • API features for stream prioritization and push resources ▪ Tomcat / Jetty / Undertow • native HTTP/2 support available in current Servlet 3.1 containers • Tomcat 8.5 / 9.0, Jetty 9.3, Undertow 1.3 / 1.4 ▪ Spring Framework 5.1 will ship dedicated Servlet 4.0 support • as well as dedicated support for the new JDK 9 HTTP client • 5.0 will focus on native HTTP/2 on top of Tomcat / Jetty / Undertow
  11. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 11 JDK 9 HTTP/2 Reactive
  12. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 12 The Importance of Reactive Architectures
  13. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 13 Reactive Streams Specification ▪ Focus on infrastructure interoperability • web servers, datastore drivers • and of course: web frameworks! ▪ Minimal API • Publisher + Subscriber/Subscription for backpressure support • repackaged into JDK 9 as java.util.concurrent.Flow ▪ Operators left up to composition libraries • RxJava 1.x / 2.0: Observable with operators like map, flatMap, take • Reactor 3.0: Flux & Mono types
  14. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 14 Reactive Streams Interaction
  15. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 15 Reactive Web Endpoints in Spring ▪ A new HTTP endpoint engine on top of a non-blocking runtime • Tomcat, Jetty, Netty, Undertow • not based on the Servlet API but adaptable to a Servlet 3.1 container ▪ A Spring MVC like endpoint model based on a reactive foundation • reusing the common Spring MVC programming model style • but accepting and returning reactive streams ▪ Separately, a functional web framework on top of the same engine • programmatic composition instead of annotation-based dispatching • in particular for microservice architectures
  16. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 16 Spring MVC ↔ Spring Web Reactive
  17. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 17 Reactive Web Controller with Repository Interop @Controller public class MyReactiveWebController { @Autowired UserRepository repository; @GetMapping("/users/{id}") public Mono<User> getUser(@PathVariable Long id) { return this.repository.findById(id); } @GetMapping("/users") public Flux<User> getUsers() { return this.repository.findAll(); } }
  18. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 18 Functional Web Endpoints in Lambda Style UserRepository repository = ...; RouterFunction<?> route = route(GET("/users/{id}"), request -> { Mono<User> user = Mono.justOrEmpty(request.pathVariable("id")) .map(Long::valueOf).then(repository::findById); return Response.ok().body(fromPublisher(user, User.class)); }) .and(route(GET("/users"), request -> { Flux<User> users = repository.findAll(); return Response.ok().body(fromPublisher(users, User.class)); }));
  19. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 19 Functional Web Endpoints with Method References RouterFunction<?> route = route(GET("/users/{id}"), handlerDelegate::getUser) .and(route(GET("/users"), handlerDelegate::getUsers)); public class MyReactiveHandlerDelegate { public Response<String> getUser(Request request) { Mono<User> user = Mono.justOrEmpty(request.pathVariable("id")) .map(Long::valueOf).then(repository::findById); return Response.ok().body(fromPublisher(user, User.class)); } public Response<String> getUsers(Request request) { Flux<User> users = repository.findAll(); return Response.ok().body(fromPublisher(users, User.class)); } }
  20. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 20 Spring Framework 5.0 GA expected in Q1 2017 JDK 8+ baseline Early JDK 9 support Embracing HTTP/2 Reactive web controllers Functional web endpoints Spring Data Reactive