|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2018 the original author or authors. |
| 2 | + * Copyright 2002-2019 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
344 | 344 | *
|
345 | 345 | * <p>By default, {@code @Bean} methods will be <em>eagerly instantiated</em> at container
|
346 | 346 | * bootstrap time. To avoid this, {@code @Configuration} may be used in conjunction with
|
347 |
| - * the {@link Lazy @Lazy} annotation to indicate that all {@code @Bean} methods declared within |
348 |
| - * the class are by default lazily initialized. Note that {@code @Lazy} may be used on |
349 |
| - * individual {@code @Bean} methods as well. |
| 347 | + * the {@link Lazy @Lazy} annotation to indicate that all {@code @Bean} methods declared |
| 348 | + * within the class are by default lazily initialized. Note that {@code @Lazy} may be used |
| 349 | + * on individual {@code @Bean} methods as well. |
350 | 350 | *
|
351 | 351 | * <h2>Testing support for {@code @Configuration} classes</h2>
|
352 | 352 | *
|
|
391 | 391 | * <ul>
|
392 | 392 | * <li>Configuration classes must be provided as classes (i.e. not as instances returned
|
393 | 393 | * from factory methods), allowing for runtime enhancements through a generated subclass.
|
394 |
| - * <li>Configuration classes must be non-final. |
| 394 | + * <li>Configuration classes must be non-final (allowing for subclasses at runtime), |
| 395 | + * unless the {@link #proxyBeanMethods() proxyBeanMethods} flag is set to {@code false} |
| 396 | + * in which case no runtime-generated subclass is necessary. |
395 | 397 | * <li>Configuration classes must be non-local (i.e. may not be declared within a method).
|
396 | 398 | * <li>Any nested configuration classes must be declared as {@code static}.
|
397 | 399 | * <li>{@code @Bean} methods may not in turn create further configuration classes
|
|
401 | 403 | *
|
402 | 404 | * @author Rod Johnson
|
403 | 405 | * @author Chris Beams
|
| 406 | + * @author Juergen Hoeller |
404 | 407 | * @since 3.0
|
405 | 408 | * @see Bean
|
406 | 409 | * @see Profile
|
|
435 | 438 | @AliasFor(annotation = Component.class)
|
436 | 439 | String value() default "";
|
437 | 440 |
|
| 441 | + /** |
| 442 | + * Specify whether {@code @Bean} methods should get proxied in order to enforce |
| 443 | + * bean lifecycle behavior, e.g. to return shared singleton bean instances even |
| 444 | + * in case of direct {@code @Bean} method calls in user code. This feature |
| 445 | + * requires method interception, implemented through a runtime-generated CGLIB |
| 446 | + * subclass which comes with limitations such as the configuration class and |
| 447 | + * its methods not being allowed to declare {@code final}. |
| 448 | + * <p>The default is {@code true}, allowing for 'inter-bean references' within |
| 449 | + * the configuration class as well as for external calls to this configuration's |
| 450 | + * {@code @Bean} methods, e.g. from another configuration class. If this is not |
| 451 | + * needed since each of this particular configuration's {@code @Bean} methods |
| 452 | + * is self-contained and designed as a plain factory method for container use, |
| 453 | + * switch this flag to {@code false} in order to avoid CGLIB subclass processing. |
| 454 | + * <p>Turning off bean method interception effectively processes {@code @Bean} |
| 455 | + * methods individually like when declared on non-{@code @Configuration} classes, |
| 456 | + * a.k.a. "@Bean Lite Mode" (see {@link Bean @Bean's javadoc}). It is therefore |
| 457 | + * behaviorally equivalent to removing the {@code @Configuration} stereotype. |
| 458 | + * @since 5.2 |
| 459 | + */ |
| 460 | + boolean proxyBeanMethods() default true; |
| 461 | + |
438 | 462 | }
|
0 commit comments