forked from spring-projects/spring-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
What's New in Spring Framework 6.x
Juergen Hoeller edited this page Sep 13, 2023
·
157 revisions
- 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).
- Lifecycle integrated pause/resume capability and parallel graceful shutdown for
ThreadPoolTaskExecutorandThreadPoolTaskScheduleras well asSimpleAsyncTaskScheduler. - Async/reactive destroy methods (e.g. on R2DBC
ConnectionFactory); see 26691. - Async/reactive cacheable methods, including corresponding support in the
Cacheinterface and inCaffeineCacheManager; see 17559 and 17920. - Reactive
@Scheduledmethods (including Kotlin coroutines); see 22924. - Observation instrumentation of
@Scheduledmethods; see 29883. - Selecting a specific target scheduler for each
@Scheduledmethod; see 20818. -
@Scheduledmethods for one-time tasks (with just an initial delay); see 31211. -
Validatorfactory methods for programmatic validator implementations; see 29890. -
Validator.validateObject(Object)with returnedErrorsandErrors.failOnErrormethod for flexible programmatic usage; see 19877. -
MethodValidationInterceptorthrowsMethodValidationExceptionsubclass ofConstraintViolationExceptionwith violations adapted toMessageSourceresolvable codes, and toErrorsinstances for@Validarguments with cascaded violations. See 29825, and umbrella issue 30645. - Support for resource patterns in
@PropertySource; see 21325. - Support for
IterableandMultiValueMapbinding inBeanWrapperandDirectFieldAccessor; see 907 and 26297. - Revised
InstantandDurationparsing (aligned with Spring Boot); see 22013. - Support for letters other than A-Z in property/field/variable names in SpEL expressions; see 30580.
- Support for registering a
MethodHandleas a SpEL function (see related documentation).
- Common
TransactionExecutionListenercontract with before/afterBegin, before/afterCommit and before/afterRollback callbacks triggered by the transaction manager (for thread-bound as well as reactive transactions); see 27479. -
@TransactionalEventListenerandTransactionalApplicationListeneralways run in the original thread, independent from an async multicaster setup; see 30244. -
@TransactionalEventListenerandTransactionalApplicationListenercan participate in reactive transactions when theApplicationEventgets published with the transaction context as its event source; see 27515. - A failed
CompletableFuturetriggers a rollback for an async transactional method; see 30018. -
DataAccessUtilsprovides variousoptionalResultmethods with ajava.util.Optionalreturn type; see 27735. - The new
JdbcClientprovides a unified facade for query/update statements on top ofJdbcTemplateandNamedParameterJdbcTemplate, with flexible parameter options as well as flexible result retrieval options; see 30931. -
SimplePropertyRowMapperandSimplePropertySqlParameterSourcestrategies for use withJdbcTemplate/NamedParameterJdbcTemplateas well asJdbcClient, providing flexible constructor/property/field mapping for result objects and named parameter holders; see 26594. -
SQLExceptionSubclassTranslatorcan be configured with an overridingcustomTranslator; see 24634. - The R2DBC
DatabaseClientprovidesbindValues(Map)for a pre-composed map of parameter values andbindProperties(Object)for parameter objects based on bean properties or record components, see 27282. - The R2DBC
DatabaseClientprovidesmapValue(Class)for plain database column values andmapProperties(Class)for result objects based on bean properties or record components; see 26021. -
BeanPropertyRowMapperandDataClassRowMapperavailable for R2DBC as well; see 30530.
- Spring MVC and WebFlux now have built-in method validation support for controller method parameters with
@Constraintannotations. That means you no longer need@Validatedat 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
ProblemDetailtype viaMessageSourceand use of customProblemDetailthrough its builder. - Spring MVC throws
NoHandlerFoundExceptionorNoResourceFoundException(new in 6.1) to allow consistent handling of 404 errors, including with an RFC 7807 error response. See 29491. - The new
RestClientis a synchronous HTTP client that offers an API similar toWebClient, using the same infrastructure asRestTemplate. See 29552. - Jetty-based
ClientHttpRequestFactoryfor use with RestTemplate and RestClient; see 30564. - JDK HttpClient-based
ClientHttpRequestFactoryfor use with RestTemplate and RestClient; see 30478. - Improved buffering in various
ClientHttpRequestFactoryimplementations; see 30557.
- Interface parameter annotations are detected for messaging handler methods as well (analogous to web handler methods).
- The SpEL-based
selectorheader support in WebSocket messaging is now disabled by default and must be explicitly enabled. See 30550 and Upgrading to 6.1 for migration details.
-
ApplicationContextfailure threshold support: avoids repeated attempts to load a failingApplicationContextin 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
nullinMockHttpServletResponse.setCharacterEncoding(). See 30341.
- Entire framework codebase based on Java 17 source code level now.
- Migration from
javaxtojakartanamespace 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).
- Upgrade to ASM 9.4 and Kotlin 1.7.
- Complete CGLIB fork with support for capturing CGLIB-generated classes.
- Comprehensive foundation for Ahead-Of-Time transformations.
- First-class support for GraalVM native images (see related Spring Boot 3 blog post).
- Basic bean property determination without
java.beans.Introspectorby 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.
-
PathMatchingResourcePatternResolveruses NIO and module path APIs for scanning, enabling support for classpath scanning within a GraalVM native image and within the Java module path, respectively. -
DefaultFormattingConversionServicesupports ISO-based defaultjava.timetype parsing.
- 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.
-
RSocket interface client based on
@RSocketExchangeservice 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.
-
HTTP interface client based on
@HttpExchangeservice 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).
-
PathPatternParserused by default (with the ability to opt intoPathMatcher). - Removal of outdated Tiles and FreeMarker JSP support.
- New
PartEventAPI to stream multipart form uploads (both on client and server). - New
ResponseEntityExceptionHandlerto customize WebFlux exceptions and render RFC 7807 error responses. -
Fluxreturn values for non-streaming media types (no longer collected toListbefore written). - Early support for Reactor Netty 2 based on Netty 5 alpha.
- JDK
HttpClientintegrated withWebClient.
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.
-
RestTemplateandWebClientare 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
FluxandMonoreturn values from controller methods.
- 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
@TestExecutionListenersand instead now rely on registration of default listeners.