|
60 | 60 | * }
|
61 | 61 | * </pre>
|
62 | 62 | *
|
63 |
| - * <h3>Scope, DependsOn, Primary, and Lazy</h3> |
| 63 | + * <h3>Profile, Scope, Lazy, DependsOn, Primary, Order</h3> |
64 | 64 | *
|
65 |
| - * <p>Note that the {@code @Bean} annotation does not provide attributes for scope, |
66 |
| - * depends-on, primary, or lazy. Rather, it should be used in conjunction with |
67 |
| - * {@link Scope @Scope}, {@link DependsOn @DependsOn}, {@link Primary @Primary}, |
68 |
| - * and {@link Lazy @Lazy} annotations to achieve those semantics. For example: |
| 65 | + * <p>Note that the {@code @Bean} annotation does not provide attributes for profile, |
| 66 | + * scope, lazy, depends-on or primary. Rather, it should be used in conjunction with |
| 67 | + * {@link Scope @Scope}, {@link Lazy @Lazy}, {@link DependsOn @DependsOn} and |
| 68 | + * {@link Primary @Primary} annotations to declare those semantics. For example: |
69 | 69 | *
|
70 | 70 | * <pre class="code">
|
71 | 71 | * @Bean
|
| 72 | + * @Profile("production") |
72 | 73 | * @Scope("prototype")
|
73 | 74 | * public MyBean myBean() {
|
74 | 75 | * // instantiate and configure MyBean obj
|
75 | 76 | * return obj;
|
76 | 77 | * }
|
77 | 78 | * </pre>
|
78 | 79 | *
|
| 80 | + * The semantics of the above-mentioned annotations match their use at the component |
| 81 | + * class level: {@code Profile} allows for selective inclusion of certain beans. |
| 82 | + * {@code @Scope} changes the bean's scope from singleton to the specified scope. |
| 83 | + * {@code @Lazy} only has an actual effect in case of the default singleton scope. |
| 84 | + * {@code @DependsOn} enforces the creation of specific other beans before this |
| 85 | + * bean will be created, in addition to any dependencies that the bean expressed |
| 86 | + * through direct references, which is typically helpful for singleton startup. |
| 87 | + * {@code @Primary} is a mechanism to resolve ambiguity at the injection point level |
| 88 | + * if a single target component needs to be injected but several beans match by type. |
| 89 | + * |
| 90 | + * <p>Additionally, {@code @Bean} methods may also declare qualifier annotations |
| 91 | + * and {@link org.springframework.core.annotation.Order @Order} values, to be |
| 92 | + * taken into account during injection point resolution just like corresponding |
| 93 | + * annotations on the corresponding component classes but potentially being very |
| 94 | + * individual per bean definition (in case of multiple definitions with the same |
| 95 | + * bean class). Qualifiers narrow the set of candidates after the initial type match; |
| 96 | + * order values determine the order of resolved elements in case of collection |
| 97 | + * injection points (with several target beans matching by type and qualifier). |
| 98 | + * |
| 99 | + * <p><b>NOTE:</b> {@code @Order} values may influence priorities at injection points |
| 100 | + * but please be aware that they do not influence singleton startup order which is an |
| 101 | + * orthogonal concern determined by dependency relationships and {@code @DependsOn} |
| 102 | + * declarations as mentioned above. Also, {@link javax.annotation.Priority} is not |
| 103 | + * available at this level since it cannot be declared on methods; its semantics can |
| 104 | + * be modelled through {@code @Order} values in combination with {@code @Primary} on |
| 105 | + * a single bean per type. |
| 106 | + * |
79 | 107 | * <h3>{@code @Bean} Methods in {@code @Configuration} Classes</h3>
|
80 | 108 | *
|
81 | 109 | * <p>Typically, {@code @Bean} methods are declared within {@code @Configuration}
|
|
143 | 171 | *
|
144 | 172 | * <h3>Bootstrapping</h3>
|
145 | 173 | *
|
146 |
| - * <p>See @{@link Configuration} Javadoc for further details including how to bootstrap |
| 174 | + * <p>See the @{@link Configuration} javadoc for further details including how to bootstrap |
147 | 175 | * the container using {@link AnnotationConfigApplicationContext} and friends.
|
148 | 176 | *
|
149 | 177 | * <h3>{@code BeanFactoryPostProcessor}-returning {@code @Bean} methods</h3>
|
|
0 commit comments