Core container improvements
- The core container additionally provides richer metadata to improve programming.
- By default Java 8 methods are detected as getter/setter methods for bean properties.
- If the target bean defines only one constructor, it does not need to specify the
@Autowired
annotation @Configuration
Classes support constructor injection.- Any SpEL expression used to specify
@EventListener
acondition
reference to a bean (for example@beanName.method()
). - Composition annotations can now be overridden with an element of type array component that contains the array property in the meta-annotation. For example,
@RequestMapping
theString[] path
can beString path
overridden . @Scheduled
and@Schedules
are now used as meta-annotations to create custom composition annotations through property overrides.@Scheduled
Any scoped beans are properly supported.
Data access improvements
jdbc:initialize-database
and jdbc:embedded-database
supports configurable separators to be applied to each script.
cache improvements
Spring 4.3 allows implementations to synchronize when a given key is called concurrently, so that the corresponding value is calculated only once. This is an optional feature, enabled by setting @Cacheable
a new sync
property . This feature introduces Cache
a breaking change to the interface, that get(Object key, Callable<T> valueLoader)
methods have been added.
Spring 4.3 also improves the cache abstraction as follows:
- SpEL expressions for cache related annotations can now refer to beans (ie
@beanName.method())
. ConcurrentMapCacheManager
and now supports serialization of cached entitiesConcurrentMapCache
via a new property. , , and are now used as meta-annotations to create custom composition annotations via property overrides.storeByValue
@Cacheable
@CacheEvict
@CachePut
@Caching
JMS improvements
@SendTo
A common reply target can now be specified at the class level.@JmsListener
and@JmsListeners
are now used as meta-annotations to create custom composition annotations through property overrides.
Web improvements
- Built-in support for HTTP HEAD and HTTP OPTIONS.
- The new combined annotations
@GetMapping
,@PostMapping
,@PutMapping
,@DeleteMapping
, and@PatchMapping
are used@RequestMapping
. - New
@RequestScope
,@SessionScope
, and composite annotations@ApplicationScope
for web scope - The new
@RestControllerAdvice
annotation is a@ControllerAdvice
semantic combination of and@ResponseBody
@ResponseStatus
Now supported at the class level and inherited by all methods- New
@SessionAttribute
annotation for accessing session properties (see example ) - New
@RequestAttribute
annotation for accessing request attributes (see example ) @ModelAttribute
Allowsbinding=false
to (see reference)- Errors and custom throws will be unified into MVC exception handlers
- Consistent handling of HTTP message conversion encodings, including default UTF-8 for multipart text content
- Static resource processing uses configured
ContentNegotiationManager
media type calculations RestTemplate
andAsyncRestTemplate
supportsDefaultUriTemplateHandler
strict URI variable encoding viaAsyncRestTemplate
Support request interception
WebSocket message improvements
@SendTo
and @SendToUser
can now be specified at the class level to share a common destination.
Test improvements
- To support Spring TestContext Framework, JUnit 4.12 or higher is now required
- new
SpringRunner
associated withSpringJUnit4ClassRunner
- Test-related annotations can now be declared on interfaces. For example, using a test interface on a Java 8 based interface
- Empty declarations will
@ContextConfiguration
now be completely ignored if a default XML file, Groovy script, or@Configuration
type is detected @Transactional
Test methods are no longer requiredpublic
(eg, in TestNG and JUnit 5)@BeforeTransaction
and are@AfterTransaction
no longer requiredpublic
and are declared on default methods of Java 8 based interfaces- The cache in the Spring TestContext Framework is
ApplicationContext
now bounded to a default maximum size of 32 and a least recently used eviction policy. The maximum size can be set by settingspring.test.context.cache.maxSize
a JVM system property or Spring configuration. ContextCustomizer
The API is used for custom testingApplicationContext
after the bean definition is loaded into the context but before the context is refreshed. Custom tools can be registered globally by third parties without the need to implement a custom oneContextLoader
.@Sql
and@SqlGroup
are now used as meta-annotations to create custom composite annotations by overriding propertiesReflectionTestUtils
Proxies are now automatically unwrapped when you set or get a field.- Server-side Spring MVC testing supports response headers with multiple values.
- Server-side Spring MVC tests parse the request content of the form data and populate request parameters.
- Server-side Spring MVC tests support mock-style assertions to invoke handler methods.
- Client-side REST testing support allows specifying how many requests are expected and whether the expected declaration order should be ignored (see 15.6.3, “Client-Side REST Testing” ).
- Client-side REST testing supports the expectation of request body form data.
Support for new class libraries and servers
- Hibernate ORM 5.2 (also good support for 4.2/4.3 and 5.0/5.1, 3.6 not recommended)
- Jackson 2.8 (with Spring 4.3, minimum Jackson 2.6+ )
- OkHttp 3.x (still supports OkHttp 2.x in parallel)
- Netty 4.1
- Undertow 1.4
- Tomcat 8.5.2 and 9.0 M6