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

Spring Framework 6

Spring Framework 6

Spring Framework 6 is a new generation of the core framework for 2023 and beyond.

Attend this talk to get an overview of the major changes and new features in the 6th generation of the Spring Framework, including Java 17 and Jakarta EE 9 baseline upgrades, first-class support for AOT processing and GraalVM native executables, and declarative HTTP clients. The talk will also briefly cover topics on the horizon such as Project Leyden, Project Loom (virtual threads), and CRaC as well as an overview of major themes for Spring Framework 6.1.

Sam Brannen

July 09, 2023
Tweet

More Decks by Sam Brannen

Other Decks in Technology

Transcript

  1. • This presentation may contain product features or functionality that

    are currently under development. • This overview of new technology represents no commitment from VMware to deliver these features in any generally available product. • Features are subject to change, and must not be included in contracts, purchase orders, or sales agreements of any kind. • Technical feasibility and market demand will affect final delivery. • Pricing and packaging for any new features/functionality/technology discussed or presented, have not been determined. • The information in this presentation is for informational purposes only and may not be incorporated into any contract. There is no commitment or obligation to deliver any items presented herein. Disclaimer
  2. • Staff Software Engineer • Java Developer for 25 years

    • Spring Framework Core Committer since 2007 • JUnit 5 Core Committer since 2015 Sam Brannen
  3. Topics • Spring Framework 6.0 • Baseline Upgrades • Declarative

    HTTP Clients • Spring AOT and GraalVM • Spring Framework 6.1 and Beyond • Project Leyden • Virtual Threads (Project Loom) • JVM Checkpoint Restore (Project CRaC)
  4. Baseline: JDK 17 LTS • Language: text blocks, switch expressions,

    instanceof pattern matching • Core libraries: collection factory methods, etc. • Type system: records, sealed classes • A great baseline for modern-day Java!
  5. Coming up: JDK 21 LTS • Language: pattern matching for

    switch, record patterns • Core libraries: sequenced collections, etc. • Runtime: virtual threads, generational ZGC • Fully supported in Spring Framework 6.1 already
  6. Baseline: Jakarta EE 9 • Servlet API 5.0: javax.servlet →

    jakarta.servlet • JPA 3.0: javax.persistence → jakarta.persistence • Bean Validation 3.0: javax.validation → jakarta.validation • Same APIs as with Java EE 8, just in a different namespace
  7. Current: Jakarta EE 10 • Servlet API 6.0: e.g. Tomcat

    10.1, Jetty 12 • Servlet 6.0 in the build, Servlet 5.0 compatibility at runtime • Servlet 6.0 for mocks in spring-test • JPA 3.1: e.g. Hibernate ORM 6.2 • Bean Validation 3.0: e.g. Hibernate Validator 8.0 • Default EE API level in Spring Boot 3
  8. Coming up: Jakarta EE 11 • JDK 21 as the

    official minimum requirement ⚠ • Servlet API 6.1 embracing virtual threads • Tomcat 11 expected to require JDK 21 as well • Optional Tomcat 11 upgrade in Spring Boot 3.3 ?
  9. Module-path and Class-path Scanning Enhancements • Module path scanning support

    for "classpath*:" resource prefix • For example, with a patched module using Maven Surefire • Class path scanning support in custom filesystems • For example, the GraalVM native image filesystem
  10. Interface-based HTTP Clients • Annotate an interface – Spring translates

    it into actual HTTP client requests • Analogous to OpenFeign/Feign but without the related issues ◦ lack of non-blocking support, dependency on third parties, etc. • Infrastructure and annotations live in Core Spring (spring-web)
  11. HTTP Client Annotations and Proxies • @HttpExchange, @PostExchange, @GetExchange, etc.

    ◦ instead of @RequestMapping, @PostMapping, etc. • Reuses several parameter-level annotations from Spring MVC ◦ @RequestHeader, @PathVariable, @RequestBody, etc. • HttpServiceProxyFactory: creates proxies for annotated client interfaces
  12. Spring AOT • Reduces startup time and memory footprint in

    production • Runtime hints for reflection, resources, serialization, proxies • Optional for optimized JVM deployments • Precondition for GraalVM native executables • Core infrastructure in Spring Framework 6 • Build tools in Spring Boot 3 • Test within a native image with JUnit 5 and GraalVM Native Build Tools AOT is a tradeoff: extra build setup and less flexibility at runtime 22
  13. GraalVM Native Image • GraalVM is the de-facto standard for

    native executables • Strong closed-world assumption, no runtime adaptations • AOT-processed application as input → native executable • Very long build time for actual native code generation A different mode of deployment with strong benefits and limitations 23
  14. Project Leyden • https://openjdk.org/projects/leyden/ • OpenJDK aims to introduce well-defined

    static images • For example, custom HotSpot-based runtime images for specific applications • Incremental approach: weaker constraints → more runtime flexibility • Strict closed-world constraints as the final goal Spring’s AOT strategy aligns with Leyden’s JVM strategy 24
  15. • Lightweight threading model within the JVM • Designed as

    virtual variant of java.lang.Thread • Better scalability for imperative programming • Not blocking an operating system thread on I/O operations Project Loom: Virtual Threads preview in JDK 19
  16. JDK 21 takes Virtual Threads out of preview • A

    regular JVM feature now, even part of an LTS release • New builder API on java.lang.Thread • New java.util.concurrent.ExecutorService variants • Seamless interoperability with existing code • Avoid synchronization around I/O operations!
  17. Virtual Threads in Spring Framework 6.1 • New virtualThreads flag

    in SimpleAsyncTaskExecutor • Dedicated VirtualThreadTaskExecutor variant • A simple replacement for existing TaskExecutor setups • Individually configurable for messaging, scheduling, etc.
  18. Virtual Threads for Spring MVC applications • Tomcat/Jetty executor setup

    for virtual threads • Latest database drivers behind JDBC and JPA • First-class setup option expected for Spring Boot 3.2 • Ideally no changes necessary in the application codebase
  19. Spring WebFlux and Virtual Threads • WebFlux: scalability through a

    reactive programming model • Stream-based access with backpressure-enabled drivers • Efficient CPU usage through non-blocking handling already • Can run potentially blocking user tasks on virtual threads • A reactive-centric web stack with blocking escape options
  20. Spring MVC and Reactive Programming • Spring MVC understands reactive

    return types as well (!) • E.g. reactive datastore access for specific web endpoints • Presence of Reactor necessary for reactive web endpoints • That aside, Spring MVC is a lean stack on virtual threads • A virtual-thread-powered web stack with reactive options
  21. Benefits of Virtual Threads • Higher scalability for existing applications

    • Or same scalability with a smaller footprint • Strong benefits for JDBC/JPA interactions • A good fit for HTTP interactions via RestTemplate • Take your Spring web applications for a test run!
  22. Project CRaC: Coordinated Restore at Checkpoint • https://github.com/CRaC/docs • Bootstrapping

    from a warmed-up HotSpot JVM image • Originally developed by Azul for OpenJDK on Linux • Adopted by Amazon for AWS Lambda SnapStart • A simple approach towards immediate JVM startup
  23. Project CRaC: Requirements • At checkpoint time, pause the application

    • No open network connections • No open file handles • At restore time, re-establish connections / listeners
  24. Project CRaC support in Spring Framework 6.1 • https://docs.spring.io/spring-framework/reference/6.1/integration/checkpoint-restore.html •

    Custom checkpoints after application startup (+ warmup) • ApplicationContext gets checkpoint/restore notifications • Propagates stop/restart signals to participating beans • org.springframework.context.Lifecycle interface
  25. Recommendations for Lifecycle implementations • For example, Spring’s own JMS

    message listener containers • Stop all asynchronous processing on Lifecycle.stop • Keep state intact; stop is not equal to destroy call • Remain able to restart async work on Lifecycle.start • When destroy follows stop, shut down completely
  26. Common Spring apps working out-of-the-box • Standard lifecycle coordination through

    the framework • Embedded Tomcat/Jetty to participate in stop/restart • Spring Boot 3.2 can support common checkpoint choices • Alternatively, custom checkpoints will be possible as well • Ideally no changes necessary in the application codebase
  27. • Spring Framework 6.1 M2 in mid July • Spring

    Boot 3.2 M1 in mid July • Release candidates in October 2023 • General availability in November 2023 • Give our milestones a try on JDK 21 EA builds! Spring Framework 6.1 + Spring Boot 3.2