Skip to content

What's New in Spring Framework 6.x

Arjen Poutsma edited this page Jul 4, 2023 · 157 revisions

What's New in Version 6.1

Core Container

  • Configuration options for virtual threads on JDK 21: a dedicated VirtualThreadTaskExecutor and a flag on SimpleAsyncTaskExecutor (also see the related GitHub issue about general compatibility with virtual threads)
  • Lifecycle integration with Project CRaC for JVM checkpoint restore (see related documentation).
  • Support for resolving JDK 21 SequencedCollection/Set/Map at injection points; see 30239.
  • Revised Instant and Duration parsing (aligned with Spring Boot); see 22013.
  • Support for letters other an A-Z in property, field, and variable names in SpEL expressions; see 30580.
  • Support for registering a MethodHandle as a SpEL function (see related documentation).
  • Async/reactive destroy methods (e.g. on R2DBC ConnectionFactory); see 26691.
  • Reactive @Scheduled methods (including Kotlin coroutines); see 22924.
  • Observation instrumentation of @Scheduled methods; see 29883.
  • Validator factory methods for programmatic validator implementations; see 29890.
  • MethodValidationInterceptor throws MethodValidationException subclass of ConstraintViolationException with violations adapted to MessageSource resolvable codes, and to Errors instances for @Valid arguments with cascaded violations. See 29825, and umbrella issue 30645.

Data Access and Transactions

  • Failed CompletableFuture triggers rollback for async transactional method; see 30018.
  • BeanPropertyRowMapper and DataClassRowMapper available for R2DBC as well; see 30530.

Web Applications

  • Spring MVC and WebFlux now have built-in method validation support for controller method parameters with @Constraint annotations. That means you no longer need @Validated at the controller class level to enable method validation via AOP proxy. Built-in method validation is layered on top of the existing argument validation for model attribute and request body arguments. The two are more tightly integrated and coordinated, e.g. avoiding cases with double validation. See Upgrading to 6.1 for migration details, 29825 for more on the built-in support in M1, and the umbrella issue 30645 for related tasks and feedback.
  • ErrorResponse allows customization of ProblemDetail type via MessageSource and use of custom ProblemDetail through its builder.
  • Spring MVC throws NoHandlerFoundException or NoResourceFoundException (new in 6.1) to allow consistent handling of 404 errors, including with an RFC 7807 error response. See 29491.
  • Jetty-based ClientHttpRequestFactory for use with RestTemplate and RestClient; see 30564.
  • JDK HttpClient-based ClientHttpRequestFactory for use with RestTemplate and RestClient; see 30478.
  • Improved buffering in various ClientHttpRequestFactory implementations; see 30557.
  • The new RestClient is a synchronous HTTP client that offers an API similar to WebClient, using the same infrastructure as RestTemplate. See 29552.

Messaging Applications

  • The SpEL-based selector header support in WebSocket messaging is now disabled by default and must be explicitly enabled. See 30550 and Upgrading to 6.1 for migration details.

Testing

  • ApplicationContext failure threshold support: avoids repeated attempts to load a failing ApplicationContext in the TestContext framework, based on a failure threshold which defaults to 1 but can be configured via a system property (see related documentation).
  • Support for recording asynchronous events with @RecordApplicationEvents. See 30020.
    • Record events from threads other than the main test thread.
    • Assert events from a separate thread – for example with Awaitility.
  • Support for null in MockHttpServletResponse.setCharacterEncoding(). See 30341.

What's New in Version 6.0

JDK 17+ and Jakarta EE 9+ Baseline

  • Entire framework codebase based on Java 17 source code level now.
  • Migration from javax to jakarta namespace for Servlet, JPA, etc.
  • Runtime compatibility with Jakarta EE 9 as well as Jakarta EE 10 APIs.
  • Compatible with latest web servers: Tomcat 10.1, Jetty 11, Undertow 2.3.
  • Early compatibility with virtual threads (in preview as of JDK 19).

General Core Revision

Core Container

  • Basic bean property determination without java.beans.Introspector by default.
  • AOT processing support in GenericApplicationContext (refreshForAotProcessing).
  • Bean definition transformation based on pre-resolved constructors and factory methods.
  • Support for early proxy class determination for AOP proxies and configuration classes.
  • PathMatchingResourcePatternResolver uses NIO and module path APIs for scanning, enabling support for classpath scanning within a GraalVM native image and within the Java module path, respectively.
  • DefaultFormattingConversionService supports ISO-based default java.time type parsing.

Data Access and Transactions

  • Support for predetermining JPA managed types (for inclusion in AOT processing).
  • JPA support for Hibernate ORM 6.1 (retaining compatibility with Hibernate ORM 5.6).
  • Upgrade to R2DBC 1.0 (including R2DBC transaction definitions).
  • Aligned data access exception translation between JDBC, R2DBC, JPA and Hibernate.
  • Removal of JCA CCI support.

Spring Messaging

  • RSocket interface client based on @RSocketExchange service interfaces.
  • Early support for Reactor Netty 2 based on Netty 5 alpha.
  • Support for Jakarta WebSocket 2.1 and its standard WebSocket protocol upgrade mechanism.

General Web Revision

  • HTTP interface client based on @HttpExchange service interfaces.
  • Support for RFC 7807 problem details.
  • Unified HTTP status code handling.
  • Support for Jackson 2.14.
  • Alignment with Servlet 6.0 (while retaining runtime compatibility with Servlet 5.0).

Spring MVC

  • PathPatternParser used by default (with the ability to opt into PathMatcher).
  • Removal of outdated Tiles and FreeMarker JSP support.

Spring WebFlux

  • New PartEvent API to stream multipart form uploads (both on client and server).
  • New ResponseEntityExceptionHandler to customize WebFlux exceptions and render RFC 7807 error responses.
  • Flux return values for non-streaming media types (no longer collected to List before written).
  • Early support for Reactor Netty 2 based on Netty 5 alpha.
  • JDK HttpClient integrated with WebClient.

Observability

Direct Observability instrumentation with Micrometer Observation in several parts of the Spring Framework. The spring-web module now requires io.micrometer:micrometer-observation:1.10+ as a compile dependency.

  • RestTemplate and WebClient are instrumented to produce HTTP client request observations.
  • Spring MVC can be instrumented for HTTP server observations using the new org.springframework.web.filter.ServerHttpObservationFilter.
  • Spring WebFlux can be instrumented for HTTP server observations using the new org.springframework.web.filter.reactive.ServerHttpObservationFilter.
  • Integration with Micrometer Context Propagation for Flux and Mono return values from controller methods.

Testing

  • Support for testing AOT-processed application contexts on the JVM or within a GraalVM native image.
  • Integration with HtmlUnit 2.64+ request parameter handling.
  • Servlet mocks (MockHttpServletRequest, MockHttpSession) are based on Servlet API 6.0 now.
  • New MockHttpServletRequestBuilder.setRemoteAddress() method.
  • The four abstract base test classes for JUnit 4 and TestNG no longer declare listeners via @TestExecutionListeners and instead now rely on registration of default listeners.