-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Spring Annotation Programming Model
This document is being introduced in conjunction with the release of Spring Framework 4.2; however, this document is still a work in progress. As such, you can expect to see multiple updates throughout the course of the 4.2.x timeline.
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.
For example, @ContextConfiguration from the spring-test module
is now declared as follows:
public @interface ContextConfiguration {
@AliasFor("locations")
String[] value() default {};
@AliasFor("value")
String[] locations() default {};
// ...
}
Similarly, composed annotations that override attributes from
meta-annotations can now use @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.
For example, one can now develop a composed annotation with a custom attribute override as follows.
@ContextConfiguration
public @interface MyTestConfig {
@AliasFor(annotation = ContextConfiguration.class, attribute = "value")
String[] xmlFiles();
// ...
}
org.springframework.cache.annotation.Cacheableorg.springframework.cache.annotation.CacheEvictorg.springframework.cache.annotation.CachePutorg.springframework.context.annotation.ComponentScan.Filterorg.springframework.context.annotation.ComponentScanorg.springframework.context.annotation.ImportResourceorg.springframework.context.annotation.Scopeorg.springframework.context.event.EventListenerorg.springframework.jmx.export.annotation.ManagedResourceorg.springframework.messaging.handler.annotation.Headerorg.springframework.messaging.handler.annotation.Payloadorg.springframework.messaging.simp.annotation.SendToUserorg.springframework.test.context.ActiveProfilesorg.springframework.test.context.ContextConfigurationorg.springframework.test.context.jdbc.Sqlorg.springframework.test.context.TestExecutionListenersorg.springframework.test.context.TestPropertySourceorg.springframework.transaction.annotation.Transactionalorg.springframework.transaction.event.TransactionalEventListenerorg.springframework.web.bind.annotation.ControllerAdviceorg.springframework.web.bind.annotation.CookieValueorg.springframework.web.bind.annotation.CrossOriginorg.springframework.web.bind.annotation.MatrixVariableorg.springframework.web.bind.annotation.RequestHeaderorg.springframework.web.bind.annotation.RequestMappingorg.springframework.web.bind.annotation.RequestParamorg.springframework.web.bind.annotation.RequestPartorg.springframework.web.bind.annotation.ResponseStatusorg.springframework.web.bind.annotation.SessionAttributesorg.springframework.web.portlet.bind.annotation.ActionMappingorg.springframework.web.portlet.bind.annotation.RenderMapping