@@ -4626,6 +4626,7 @@ The corresponding bean definitions appear as follows.
4626
4626
----
4627
4627
4628
4628
4629
+
4629
4630
[[beans-autowired-annotation-qualifiers]]
4630
4631
=== Fine-tuning annotation-based autowiring with qualifiers
4631
4632
@@ -5043,7 +5044,6 @@ Generic qualifiers also apply when autowiring Lists, Maps and Arrays:
5043
5044
5044
5045
5045
5046
5046
-
5047
5047
[[beans-custom-autowire-configurer]]
5048
5048
=== CustomAutowireConfigurer
5049
5049
@@ -6138,27 +6138,37 @@ The `AppConfig` class above would be equivalent to the following Spring `<beans/
6138
6138
</beans>
6139
6139
----
6140
6140
6141
- .Full @Configuration vs 'lite' @Beans mode?
6141
+ .Full @Configuration vs 'lite' @Bean mode?
6142
6142
****
6143
6143
When `@Bean` methods are declared within classes that are __not__ annotated with
6144
- `@Configuration` they are referred to as being processed in a 'lite' mode. For example,
6145
- bean methods declared in a `@Component` or even in a __plain old class__ will be
6146
- considered 'lite'.
6147
-
6148
- Unlike full `@Configuration`, lite `@Bean` methods cannot easily declare inter-bean
6149
- dependencies. Usually one `@Bean` method should not invoke another `@Bean` method when
6150
- operating in 'lite' mode.
6151
-
6152
- Only using `@Bean` methods within `@Configuration` classes is a recommended approach of
6153
- ensuring that 'full' mode is always used. This will prevent the same `@Bean` method from
6154
- accidentally being invoked multiple times and helps to reduce subtle bugs that can be
6155
- hard to track down when operating in 'lite' mode.
6144
+ `@Configuration` they are referred to as being processed in a 'lite' mode. Bean methods
6145
+ declared in a `@Component` or even in a __plain old class__ will be considered 'lite',
6146
+ with a different primary purpose of the containing class and an `@Bean` method just
6147
+ being a sort of bonus there. For example, service components may expose management views
6148
+ to the container through an additional `@Bean` method on each applicable component class.
6149
+ In such scenarios, `@Bean` methods are a simple general-purpose factory method mechanism.
6150
+
6151
+ Unlike full `@Configuration`, lite `@Bean` methods cannot declare inter-bean dependencies.
6152
+ Instead, they operate on their containing component's internal state and optionally on
6153
+ arguments that they may declare. Such an `@Bean` method should therefore not invoke other
6154
+ `@Bean` methods; each such method is literally just a factory method for a particular
6155
+ bean reference, without any special runtime semantics. The positive side-effect here is
6156
+ that no CGLIB subclassing has to be applied at runtime, so there are no limitations in
6157
+ terms of class design (i.e. the containing class may nevertheless be `final` etc).
6158
+
6159
+ In common scenarios, `@Bean` methods are to be declared within `@Configuration` classes,
6160
+ ensuring that 'full' mode is always used and that cross-method references will therefore
6161
+ get redirected to the container's lifecycle management. This will prevent the same
6162
+ `@Bean` method from accidentally being invoked through a regular Java call which helps
6163
+ to reduce subtle bugs that can be hard to track down when operating in 'lite' mode.
6156
6164
****
6157
6165
6158
6166
The `@Bean` and `@Configuration` annotations will be discussed in depth in the sections
6159
6167
below. First, however, we'll cover the various ways of creating a spring container using
6160
6168
Java-based configuration.
6161
6169
6170
+
6171
+
6162
6172
[[beans-java-instantiating-container]]
6163
6173
=== Instantiating the Spring container using AnnotationConfigApplicationContext
6164
6174
0 commit comments