From 4d6f143f85e8c69aa10073826566b7baa6926479 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Thu, 30 Jul 2015 22:33:13 +0200 Subject: [PATCH] Add link to 'Spring Annotation Programming Model' Wiki page Issue: SPR-11515 --- src/asciidoc/appendix.adoc | 6 ++++ src/asciidoc/core-beans.adoc | 54 ++++++++++++++++++++++++------------ src/asciidoc/testing.adoc | 1 + 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/asciidoc/appendix.adoc b/src/asciidoc/appendix.adoc index 72e916fde2..b5ebbae7ac 100644 --- a/src/asciidoc/appendix.adoc +++ b/src/asciidoc/appendix.adoc @@ -7,6 +7,12 @@ Migration guides for upgrading from previous releases of the Spring Framework ar https://github.com/spring-projects/spring-framework/wiki/Migrating-from-earlier-versions-of-the-spring-framework[Wiki page]. +[[annotation-programming-model]] +== Spring Annotation Programming Model +Spring's annotation programming model is documented in the +https://github.com/spring-projects/spring-framework/wiki/Spring-Annotation-Programming-Model[Spring Framework Wiki]. + + [[classic-spring]] == Classic Spring Usage This appendix discusses some classic Spring usage patterns as a reference for developers diff --git a/src/asciidoc/core-beans.adoc b/src/asciidoc/core-beans.adoc index 6d126c503a..c240b67813 100644 --- a/src/asciidoc/core-beans.adoc +++ b/src/asciidoc/core-beans.adoc @@ -5048,10 +5048,10 @@ supported as a marker for automatic exception translation in your persistence la [[beans-meta-annotations]] === Meta-annotations -Many of the annotations provided by Spring can be used as "meta-annotations" in -your own code. A meta-annotation is simply an annotation that can be applied to another +Many of the annotations provided by Spring can be used as __meta-annotations__ in your +own code. A meta-annotation is simply an annotation that can be applied to another annotation. For example, the `@Service` annotation mentioned above is meta-annotated with -with `@Component`: +`@Component`: [source,java,indent=0] [subs="verbatim,quotes"] @@ -5063,36 +5063,56 @@ with `@Component`: public @interface Service { // .... - } ---- -Meta-annotations can also be combined together to create __composed annotations__. For -example, the `@RestController` annotation from Spring MVC is __composed__ of -`@Controller` and `@ResponseBody`. - -With the exception of the `value` attribute, composed annotations may redeclare -attributes from meta-annotations to allow user customization. This can be particularly -useful when you want to only expose a subset of the meta-annotation's attributes. For -example, here is a custom `@Scope` annotation that hardcodes the scope name to `session` -but still allows customization of the `proxyMode`. +Meta-annotations can also be combined to create __composed annotations__. For example, +the `@RestController` annotation from Spring MVC is __composed__ of `@Controller` and +`@ResponseBody`. +In addition, composed annotations may optionally redeclare attributes from +meta-annotations to allow user customization. This can be particularly useful when you +want to only expose a subset of the meta-annotation's attributes. For example, the +following is a custom `@Scope` annotation that hardcodes the scope name to `session` but +still allows customization of the `proxyMode`. [source,java,indent=0] [subs="verbatim,quotes"] ---- - @Target({ElementType.TYPE}) + @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) - @Documented **@Scope("session")** public @interface SessionScope { - ScopedProxyMode proxyMode() default ScopedProxyMode.DEFAULT - + ScopedProxyMode proxyMode() default ScopedProxyMode.DEFAULT; } ---- +`@SessionScope` can then be used without declaring the `proxyMode` as follows: +[source,java,indent=0] +[subs="verbatim,quotes"] +---- + @Service + **@SessionScope** + public class SessionScopedUserService implements UserService { + // ... + } +---- + +Or with an overridden value for the `proxyMode` as follows: + +[source,java,indent=0] +[subs="verbatim,quotes"] +---- + @Service + **@SessionScope(proxyMode = ScopedProxyMode.TARGET_CLASS)** + public class SessionScopedService { + // ... + } +---- + +For further details, consult the <>. [[beans-scanning-autodetection]] diff --git a/src/asciidoc/testing.adoc b/src/asciidoc/testing.adoc index 439edc5b8d..90916b0967 100644 --- a/src/asciidoc/testing.adoc +++ b/src/asciidoc/testing.adoc @@ -1199,6 +1199,7 @@ configuration of individual test classes as follows: public class UserRepositoryTests { } ---- +For further details, consult the <>. [[testcontext-framework]]