@Bean
get detected and processed on Java 8 default methods as well,
allowing for composing a configuration class from interfaces with default @Bean
methods.
@Import
with regular component classes now, allowing
for a mix of imported configuration classes and component classes.
@Order
value, getting processed in a corresponding
order (e.g. for overriding beans by name) even when detected through classpath scanning.
@Resource
injection points support an @Lazy
declaration, analogous to @Autowired
,
receiving a lazy-initializing proxy for the requested target bean.
The application event infrastructure now offers an annotation-based model as well as the ability to publish any arbitrary event.
@EventListener
to consume events.
@TransactionalEventListener
provides transaction-bound event support.
Spring Framework 4.2 introduces first-class support for declaring and
looking up aliases for annotation attributes. The new @AliasFor
annotation can be used to declare a pair of aliased attributes within
a single annotation or to declare an alias from one attribute in a
custom composed annotation to an attribute in a meta-annotation.
@AliasFor
support
in order to provide meaningful aliases for their value
attributes:
@Cacheable
, @CacheEvict
, @CachePut
, @ComponentScan
,
@ComponentScan.Filter
, @ImportResource
, @Scope
, @ManagedResource
,
@Header
, @Payload
, @SendToUser
, @ActiveProfiles
,
@ContextConfiguration
, @Sql
, @TestExecutionListeners
,
@TestPropertySource
, @Transactional
, @ControllerAdvice
,
@CookieValue
, @CrossOrigin
, @MatrixVariable
, @RequestHeader
,
@RequestMapping
, @RequestParam
, @RequestPart
, @ResponseStatus
,
@SessionAttributes
, @ActionMapping
, @RenderMapping
,
@EventListener
, @TransactionalEventListener
.
@ContextConfiguration
from the spring-test
module
is now declared as follows:
public @interface ContextConfiguration { @AliasFor("locations") String[] value() default {}; @AliasFor("value") String[] locations() default {}; // ... }
@AliasFor
for fine-grained control
over exactly which attributes are overridden within an annotation
hierarchy. In fact, it is now possible to declare an alias for the
value
attribute of a meta-annotation.
@ContextConfiguration public @interface MyTestConfig { @AliasFor(annotation = ContextConfiguration.class, attribute = "value") String[] xmlFiles(); // ... }
See Spring Annotation Programming Model.
AnnotationAttributes
instances)
can be synthesized (i.e., converted) into an annotation.
DirectFieldAccessor
) have been aligned with the current
property-based data binding (BeanWrapper
). In particular, field-based binding now supports
navigation for Collections, Arrays, and Maps.
DefaultConversionService
now provides out-of-the-box converters for Stream
, Charset
,
Currency
, and TimeZone
. Such converters can be added individually to any arbitrary
ConversionService
as well.
DefaultFormattingConversionService
comes with out-of-the-box support for the value types
in JSR-354 Money & Currency (if the 'javax.money' API is present on the classpath): namely,
MonetaryAmount
and CurrencyUnit
. This includes support for applying @NumberFormat
.
@NumberFormat
can now be used as a meta-annotation.
JavaMailSenderImpl
has a new testConnection()
method for checking connectivity to the server.
ScheduledTaskRegistrar
exposes scheduled tasks.
commons-pool2
is now supported for a pooling AOP CommonsPool2TargetSource
.
StandardScriptFactory
as a JSR-223 based mechanism for scripted beans,
exposed through the lang:std
element in XML. Supports e.g. JavaScript and JRuby.
(Note: JRubyScriptFactory and lang:jruby
are deprecated now, in favor of using JSR-223.)
javax.transaction.Transactional
is now supported via AspectJ.
SimpleJdbcCallOperations
now supports named binding.
org.springframework.orm.hibernate5
package).
<jdbc:embedded-database>
supports a new database-name
attribute.
See "Testing Improvements" below for further details.
autoStartup
attribute can be controlled via JmsListenerContainerFactory
.
Destination
can now be configured per listener container.
@SendTo
annotation can now use a SpEL expression.
JmsResponse
@JmsListener
is now a repeatable annotation to declare several JMS containers on the same
method (use the newly introduced @JmsListeners
if you’re not using Java8 yet).
@CrossOrigin
) configuration. See Chapter 26, CORS Support for details.
HTTP caching updates:
CacheControl
builder; plugged into ResponseEntity
, WebContentGenerator
,
ResourceHttpRequestHandler
.
WebRequest
.
@RequestMapping
as a meta-annotation.
AbstractHandlerMethodMapping
to register and unregister request
mappings at runtime.
createDispatcherServlet
method in AbstractDispatcherServletInitializer
to
further customize the DispatcherServlet
instance to use.
HandlerMethod
as a method argument on @ExceptionHandler
methods, especially
handy in @ControllerAdvice
components.
java.util.concurrent.CompletableFuture
as an @Controller
method return value type.
HttpHeaders
and for serving static resources.
@ResponseStatus
detected on nested exceptions.
UriTemplateHandler
extension point in the RestTemplate
.
DefaultUriTemplateHandler
exposes baseUrl
property and path segment encoding options.
RestTemplate
.
baseUrl
alternative for methods in MvcUriComponentsBuilder
.
RequestBodyAdvice
extension point and built-in implementation to support Jackson’s
@JsonView
on @RequestBody
method arguments.
List<Foo>
.
ScriptTemplateView
as a JSR-223 based mechanism for scripted web views,
with a focus on JavaScript view templating on Nashorn (JDK 8).
Expose presence information about connected users and subscriptions:
SimpUserRegistry
exposed as a bean named "userRegistry".
StompSubProtocolErrorHandler
extension point to customize and control STOMP ERROR frames to clients.
@MessageExceptionHandler
methods via @ControllerAdvice
components.
SimpleBrokerMessageHandler
.
@SendTo
and @SendToUser
can contain destination variable placeholders.
@JsonView
supported for return values on @MessageMapping
and @SubscribeMapping
methods.
ListenableFuture
and CompletableFuture
as return value types from
@MessageMapping
and @SubscribeMapping
methods.
MarshallingMessageConverter
for XML payloads.
JUnit-based integration tests can now be executed with JUnit rules instead of the
SpringJUnit4ClassRunner
. This allows Spring-based integration tests to be run with
alternative runners like JUnit’s Parameterized
or third-party runners such as the
MockitoJUnitRunner
.
The Spring MVC Test framework now provides first-class support for HtmlUnit, including integration with Selenium’s WebDriver, allowing for page-based web application testing without the need to deploy to a Servlet container.
AopTestUtils
is a new testing utility that allows developers to
obtain a reference to the underlying target object hidden behind one
or more Spring proxies.
ReflectionTestUtils
now supports setting and getting static
fields,
including constants.
@ActiveProfiles
is now retained in order to support use cases such
as Spring Boot’s ConfigFileApplicationListener
which loads
configuration files based on the names of active profiles.
@DirtiesContext
supports new BEFORE_METHOD
, BEFORE_CLASS
, and
BEFORE_EACH_TEST_METHOD
modes for closing the ApplicationContext
before a test — for example, if some rogue (i.e., yet to be
determined) test within a large test suite has corrupted the original
configuration for the ApplicationContext
.
@Commit
is a new annotation that may be used as a direct replacement for
@Rollback(false)
.
@Rollback
may now be used to configure class-level default rollback semantics.
@TransactionConfiguration
is now deprecated and will be removed in a
subsequent release.
@Sql
now supports execution of inlined SQL statements via a new
statements
attribute.
ContextCache
that is used for caching ApplicationContexts
between tests is now a public API with a default implementation that
can be replaced for custom caching needs.
DefaultTestContext
, DefaultBootstrapContext
, and
DefaultCacheAwareContextLoaderDelegate
are now public classes in the
support
subpackage, allowing for custom extensions.
TestContext
.
MvcResult
details can now be logged
at DEBUG
level or written to a custom OutputStream
or Writer
. See
the new log()
, print(OutputStream)
, and print(Writer)
methods in
MockMvcResultHandlers
for details.
database-name
attribute in
<jdbc:embedded-database>
, allowing developers to set unique names
for embedded databases –- for example, via a SpEL expression or a
property placeholder that is influenced by the current active bean
definition profiles.
Embedded databases can now be automatically assigned a unique name, allowing common test database configuration to be reused in different ApplicationContexts within a test suite.