@@ -5048,10 +5048,10 @@ supported as a marker for automatic exception translation in your persistence la
5048
5048
[[beans-meta-annotations]]
5049
5049
=== Meta-annotations
5050
5050
5051
- Many of the annotations provided by Spring can be used as "meta-annotations" in
5052
- your own code. A meta-annotation is simply an annotation that can be applied to another
5051
+ Many of the annotations provided by Spring can be used as __meta-annotations__ in your
5052
+ own code. A meta-annotation is simply an annotation that can be applied to another
5053
5053
annotation. For example, the `@Service` annotation mentioned above is meta-annotated with
5054
- with `@Component`:
5054
+ `@Component`:
5055
5055
5056
5056
[source,java,indent=0]
5057
5057
[subs="verbatim,quotes"]
@@ -5063,36 +5063,56 @@ with `@Component`:
5063
5063
public @interface Service {
5064
5064
5065
5065
// ....
5066
-
5067
5066
}
5068
5067
----
5069
5068
5070
- Meta-annotations can also be combined together to create __composed annotations__. For
5071
- example, the `@RestController` annotation from Spring MVC is __composed__ of
5072
- `@Controller` and `@ResponseBody`.
5073
-
5074
- With the exception of the `value` attribute, composed annotations may redeclare
5075
- attributes from meta-annotations to allow user customization. This can be particularly
5076
- useful when you want to only expose a subset of the meta-annotation's attributes. For
5077
- example, here is a custom `@Scope` annotation that hardcodes the scope name to `session`
5078
- but still allows customization of the `proxyMode`.
5069
+ Meta-annotations can also be combined to create __composed annotations__. For example,
5070
+ the `@RestController` annotation from Spring MVC is __composed__ of `@Controller` and
5071
+ `@ResponseBody`.
5079
5072
5073
+ In addition, composed annotations may optionally redeclare attributes from
5074
+ meta-annotations to allow user customization. This can be particularly useful when you
5075
+ want to only expose a subset of the meta-annotation's attributes. For example, the
5076
+ following is a custom `@Scope` annotation that hardcodes the scope name to `session` but
5077
+ still allows customization of the `proxyMode`.
5080
5078
5081
5079
[source,java,indent=0]
5082
5080
[subs="verbatim,quotes"]
5083
5081
----
5084
- @Target({ ElementType.TYPE} )
5082
+ @Target(ElementType.TYPE)
5085
5083
@Retention(RetentionPolicy.RUNTIME)
5086
- @Documented
5087
5084
**@Scope("session")**
5088
5085
public @interface SessionScope {
5089
5086
5090
- ScopedProxyMode proxyMode() default ScopedProxyMode.DEFAULT
5087
+ ScopedProxyMode proxyMode() default ScopedProxyMode.DEFAULT;
5088
+ }
5089
+ ----
5090
+
5091
+ `@SessionScope` can then be used without declaring the `proxyMode` as follows:
5091
5092
5093
+ [source,java,indent=0]
5094
+ [subs="verbatim,quotes"]
5095
+ ----
5096
+ @Service
5097
+ **@SessionScope**
5098
+ public class SessionScopedUserService implements UserService {
5099
+ // ...
5092
5100
}
5093
5101
----
5094
5102
5103
+ Or with an overridden value for the `proxyMode` as follows:
5104
+
5105
+ [source,java,indent=0]
5106
+ [subs="verbatim,quotes"]
5107
+ ----
5108
+ @Service
5109
+ **@SessionScope(proxyMode = ScopedProxyMode.TARGET_CLASS)**
5110
+ public class SessionScopedService {
5111
+ // ...
5112
+ }
5113
+ ----
5095
5114
5115
+ For further details, consult the <<annotation-programming-model,Spring Annotation Programming Model>>.
5096
5116
5097
5117
5098
5118
[[beans-scanning-autodetection]]
0 commit comments