Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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)

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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; }

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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!

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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 getUser(@PathVariable Long id) { return this.repository.findById(id); } @GetMapping("/users") public Flux getUsers() { return this.repository.findAll(); } }

Slide 18

Slide 18 text

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 = 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 users = repository.findAll(); return Response.ok().body(fromPublisher(users, User.class)); }));

Slide 19

Slide 19 text

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 getUser(Request request) { Mono user = Mono.justOrEmpty(request.pathVariable("id")) .map(Long::valueOf).then(repository::findById); return Response.ok().body(fromPublisher(user, User.class)); } public Response getUsers(Request request) { Flux users = repository.findAll(); return Response.ok().body(fromPublisher(users, User.class)); } }

Slide 20

Slide 20 text

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