Releases
6.1.x
Core Container
- General compatibility with virtual threads and JDK 21 overall.
- Configuration options for virtual threads: a dedicated VirtualThreadTaskExecutor and a virtual threads mode on SimpleAsyncTaskExecutor, plus an analogous SimpleAsyncTaskScheduler with a new-thread-per-task strategy and a virtual threads mode.
- Lifecycle integration with Project CRaC for JVM checkpoint restore (see related documentation), including a
-Dspring.context.checkpoint=onRefreshoption. - Lifecycle integrated pause/resume capability and parallel graceful shutdown for
ThreadPoolTaskExecutorandThreadPoolTaskScheduleras well asSimpleAsyncTaskScheduler. - A
-Dspring.context.exit=onRefreshoption is available with AppCDS training runs as the main use-case - Reachability metadata contribution improvements, preparing for upcoming GraalVM changes: missing reachability metadata will be soon reported as runtime exceptions for better developer experience.
- Async/reactive destroy methods (e.g. on R2DBC ConnectionFactory);.
- Async/reactive cacheable methods, including corresponding support in the Cache interface and in CaffeineCacheManager; see 17559 and 17920.
- Reactive
@Scheduledmethods (including Kotlin coroutines) - Selecting a specific target scheduler for each
@Scheduledmethod @Scheduledmethods for one-time tasks (with just an initial delay)- Observation instrumentation of @Scheduled methods
- Spring Framework will not produce observations out-of-the-box for @Async or @EventListener annotated methods, but will help you with propagating context (e.g. MDC logging with the current trace id) for the execution of those methods. See the new ContextPropagatingTaskDecorator, the relevant reference documentation section and issue 31130.
- Validator factory methods for programmatic validator implementations
- Validator.validateObject(Object) with returned Errors and Errors.failOnError method for flexible programmatic usage
- 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.
- Support for resource patterns in @PropertySource
- Support for Iterable and MultiValueMap binding in BeanWrapper and DirectFieldAccessor; see 907 and 26297.
- Revised Instant and Duration parsing (aligned with Spring Boot)
- Support for letters other than A-Z in property/field/variable names in SpEL expressions
- Support for registering a MethodHandle as a SpEL function (see related documentation).
- Spring AOP now supports Coroutines
Data Access and Transactions
- Common TransactionExecutionListener contract with before/afterBegin, before/afterCommit and before/afterRollback callbacks triggered by the transaction manager (for thread-bound as well as reactive transactions)
- @TransactionalEventListener and TransactionalApplicationListener always run in the original thread, independent from an async multicaster setup
- @TransactionalEventListener and TransactionalApplicationListener can participate in reactive transactions when the ApplicationEvent gets published with the transaction context as its event source
- A failed CompletableFuture triggers a rollback for an async transactional method
- DataAccessUtils provides various optionalResult methods with a java.util.Optional return type
- The new JdbcClient provides a unified facade for query/update statements on top of JdbcTemplate and NamedParameterJdbcTemplate, with flexible parameter options as well as flexible result retrieval options
- SimplePropertyRowMapper and SimplePropertySqlParameterSource strategies for use with JdbcTemplate/NamedParameterJdbcTemplate as well as JdbcClient, providing flexible constructor/property/field mapping for result objects and named parameter holders
- SQLExceptionSubclassTranslator can be configured with an overriding customTranslator
- The R2DBC DatabaseClient provides bindValues(Map) for a pre-composed map of parameter values and bindProperties(Object) for parameter objects based on bean properties or record components, see 27282.
- The R2DBC DatabaseClient provides mapValue(Class) for plain database column values and mapProperties(Class) for result objects based on bean properties or record components
- BeanPropertyRowMapper and DataClassRowMapper available for R2DBC as well
- JpaTransactionManager with HibernateJpaDialect translates Hibernate commit/rollback exceptions to DataAccessException subclasses wherever possible, e.g. to CannotAcquireLockException, aligned with the exception hierarchy thrown from persistence exception translation for repository operations. See 31274 for the primary motivation: PostgreSQL serialization failures.
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, and umbrella issue 30645 for all related tasks and feedback.
- Method validation is supported with method parameters that are collections, arrays, or maps of objects.
- The HandlerMethodValidationException raised by the new built-in method validation exposes a Visitor API to process validation errors by controller method parameter type, e.g. @RequestParameter, @PathVariable, etc.
- MethodValidationInterceptor supports validation of Mono and Flux method parameters, see issue 20781.
- Spring MVC raises NoHandlerFoundException by default if there is no matching handler, and ResponseStatusException(NOT_FOUND) if there is no matching static resource, and also handles these with the aim of consistent handling for 404 errors out of the box, including RFC 7807 responses. See 29491.
- ErrorResponse allows customization of ProblemDetail type via MessageSource and use of custom ProblemDetail through its builder.
- Spring MVC resets the Servlet response buffer prior to handling error and rendering an error response.
- DataBinder now supports constructor binding where argument values are looked up through a NameResolver (e.g. in the HTTP request parameters map), and those lookups can be customized through an @BindParam annotation. This also supports nested object structures through the invocation of constructors necessary to initialize constructor parameters. The feature is integrated in the data binding of Spring MVC and WebFlux and provides a safer option for data binding of expected parameters only, see Model Design for more details. Spring MVC and WebFlux now support data binding via constructors, including nested objects constructors
- WebFlux provides option for blocking execution of controller methods with synchronous signature on a different Executor such as the VirtualThreadTaskExecutor, see Blocking Execution in the reference documentation.
- SseEmitter now formats data with newlines according to the SSE format.
- New RestClient, a synchronous HTTP client that offers an API similar to WebClient, but sharing infrastructure with the RestTemplate. See 29552.
- Jetty-based ClientHttpRequestFactory for use with RestTemplate and RestClient
- JDK HttpClient-based ClientHttpRequestFactory for use with RestTemplate and RestClient
- Reactor Netty-based ClientHttpRequestFactory for use with RestTemplate and RestClient
- Improved buffering in various ClientHttpRequestFactory implementations
- HTTP Interface client built-in adapters for the new RestClient and RestTemplate in addition to the existing adapter for the reactive WebClient.
- HTTP Interface client supports MultipartFile as an input method parameter.
- HTTP Interface client supports UriBuilderFactory as an input method parameter to use instead of the one the underlying is configured with, e.g. if necessary to vary the baseURL dynamically.
- The @HttpExchange annotation used on HTTP interface methods is now supported for server side handling in Spring MVC and WebFlux as an alternative to @RequestMapping, see @HttpExchange for more details and guidance.
- JVM checkpoint restore support added to Reactor Netty-based ClientHttpRequestFactory for use with RestTemplate and RestClient and ClientHttpConnector for use with WebClient; see 31280, 31281 and 31180.
- General Coroutines support revision in WebFlux, which includes CoroutineContext propagation in CoWebFilter, CoroutineContext propagation in coRouter DSL with filter, a new context function in coRouter DSL, Support for @ModelAttribute with suspending function in WebFlux and consistent usage of the Mono variant of awaitSingle().
- Support Kotlin parameter default and optional values in HTTP handler methods; see 21139 and 29820.
Messaging Applications
- STOMP messaging supports a new preserveReceiveOrder config option for ordered processing of messages received from a given client. That's in addition to the existing preservePublishOrder flag for messages published to clients. See the Order of Messages section of the reference docs.
- The @RSocketExchange annotation used on RSocket interface methods is now supported for responder side handling as an alternative to @MessageMapping, see @RSocketExchange for more details and guidance.
- Interface parameter annotations are detected for messaging handler methods as well (analogous to web handler methods).
- 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.
- Observability support for JMS. We now produce observations when publishing messages with JmsTemplate and when processing messages with MessageListener or @JmsListener. See the reference docs section and issue 30335.
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.
- MockMvc now supports initialization of filters with init parameters and mapping to specific dispatch types.
- MockMvcWebTestClient now supports the RequestPostProcessor hook which can for example allow varying user identity across tests. See 31298.
- MockRestServiceServer supports the new RestClient in addition to the RestTemplate.
- Support for null in MockHttpServletResponse.setCharacterEncoding(). See 30341.