On this page
6. New Features and Enhancements in Spring Framework 4.3
Version 4.3 included a number of improvements, as described in the following sections:
- Section 6.1, “Core Container Improvements”
- Section 6.2, “Data Access Improvements”
- Section 6.3, “Caching Improvements”
- Section 6.4, “JMS Improvements”
- Section 6.5, “Web Improvements”
- Section 6.6, “WebSocket Messaging Improvements”
- Section 6.7, “Testing Improvements”
- Section 6.8, “Support for new library and server generations”
- Core container exceptions provide richer metadata to evaluate programmatically.
- Java 8 default methods get detected as bean property getters/setters.
- Lazy candidate beans are not being created in case of injecting a primary bean.
- It is no longer necessary to specify the
@Autowiredannotation if the target bean only defines one constructor. @Configurationclasses support constructor injection.- Any SpEL expression used to specify the
conditionof an@EventListenercan now refer to beans (e.g.@beanName.method()). - Composed annotations can now override array attributes in meta-annotations with a single element of the component type of the array. For example, the
String[] pathattribute of@RequestMappingcan be overridden withString pathin a composed annotation. @PersistenceContext/@PersistenceUnitselects a primaryEntityManagerFactorybean if declared as such.@Scheduledand@Schedulesmay now be used as meta-annotations to create custom composed annotations with attribute overrides.@Scheduledis properly supported on beans of any scope.
jdbc:initialize-databaseandjdbc:embedded-databasesupport a configurable separator to be applied to each script.
Spring 4.3 allows concurrent calls on a given key to be synchronized so that the value is only computed once. This is an opt-in feature that should be enabled via the new sync attribute on @Cacheable. This features introduces a breaking change in the Cache interface as a get(Object key, Callable<T> valueLoader) method has been added.
Spring 4.3 also improves the caching abstraction as follows:
- SpEL expressions in caches-related annotations can now refer to beans (i.e.
@beanName.method()). ConcurrentMapCacheManagerandConcurrentMapCachenow support the serialization of cache entries via a newstoreByValueattribute.@Cacheable,@CacheEvict,@CachePut, and@Cachingmay now be used as meta-annotations to create custom composed annotations with attribute overrides.
@SendTocan now be specified at the class level to share a common reply destination.@JmsListenerand@JmsListenersmay now be used as meta-annotations to create custom composed annotations with attribute overrides.
- Built-in support for HTTP HEAD and HTTP OPTIONS.
New
@GetMapping,@PostMapping,@PutMapping,@DeleteMapping, and@PatchMappingcomposed annotations for@RequestMapping.- See Composed @RequestMapping Variants for details.
New
@RequestScope,@SessionScope, and@ApplicationScopecomposed annotations for web scopes.- See Request scope, Session scope, and Application scope for details.
- New
@RestControllerAdviceannotation with combined@ControllerAdvicewith@ResponseBodysemantics. @ResponseStatusis now supported at the class level and inherited by all methods.- New
@SessionAttributeannotation for access to session attributes (see example). - New
@RequestAttributeannotation for access to request attributes (see example). @ModelAttributeallows preventing data binding viabinding=falseattribute (see reference).@PathVariablemay be declared as optional (for use on@ModelAttributemethods).- Consistent exposure of Errors and custom Throwables to MVC exception handlers.
- Consistent charset handling in HTTP message converters, including a UTF-8 default for multipart text content.
- Static resource handling uses the configured
ContentNegotiationManagerfor media type determination. RestTemplateandAsyncRestTemplatesupport strict URI variable encoding viaDefaultUriTemplateHandler.AsyncRestTemplatesupports request interception.
@SendToand@SendToUsercan now be specified at class-level to share a common destination.
- The JUnit support in the Spring TestContext Framework now requires JUnit 4.12 or higher.
- New
SpringRunneralias for theSpringJUnit4ClassRunner. - Test related annotations may now be declared on interfaces — for example, for use with test interfaces that make use of Java 8 based interface default methods.
- An empty declaration of
@ContextConfigurationcan now be completely omitted if default XML files, Groovy scripts, or@Configurationclasses are detected. @Transactionaltest methods are no longer required to bepublic(e.g., in TestNG and JUnit 5).@BeforeTransactionand@AfterTransactionmethods are no longer required to bepublicand may now be declared on Java 8 based interface default methods.- The
ApplicationContextcache in the Spring TestContext Framework is now bounded with a default maximum size of 32 and a least recently used eviction policy. The maximum size can be configured by setting a JVM system property or Spring property calledspring.test.context.cache.maxSize. - New
ContextCustomizerAPI for customizing a testApplicationContextafter bean definitions have been loaded into the context but before the context has been refreshed. Customizers can be registered globally by third parties, foregoing the need to implement a customContextLoader. @Sqland@SqlGroupmay now be used as meta-annotations to create custom composed annotations with attribute overrides.ReflectionTestUtilsnow automatically unwraps proxies when setting or getting a field.- Server-side Spring MVC Test supports expectations on response headers with multiple values.
- Server-side Spring MVC Test parses form data request content and populates request parameters.
- Server-side Spring MVC Test supports mock-like assertions for invoked handler methods.
- Client-side REST test support allows indicating how many times a request is expected and whether the order of declaration for expectations should be ignored (see Section 15.6.3, “Client-Side REST Tests”).
- Client-side REST Test supports expectations for form data in the request body.
- Hibernate ORM 5.2 (still supporting 4.2/4.3 and 5.0/5.1 as well, with 3.6 deprecated now)
- Hibernate Validator 5.3 (minimum remains at 4.3)
- Jackson 2.8 (minimum raised to Jackson 2.6+ as of Spring 4.3)
- OkHttp 3.x (still supporting OkHttp 2.x side by side)
- Tomcat 8.5 as well as 9.0 milestones
- Netty 4.1
- Undertow 1.4
- WildFly 10.1
Furthermore, Spring Framework 4.3 embeds the updated ASM 5.1, CGLIB 3.2.4, and Objenesis 2.4 in spring-core.jar.