Skip to content

Commit 2086886

Browse files
committed
Clarify the behaviour of @Bean(autowireCandidate=false)
1 parent 11db31a commit 2086886

File tree

1 file changed

+10
-0
lines changed
  • spring-context/src/main/java/org/springframework/context/annotation

1 file changed

+10
-0
lines changed

spring-context/src/main/java/org/springframework/context/annotation/Bean.java

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.lang.annotation.RetentionPolicy;
2323
import java.lang.annotation.Target;
2424

25+
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
2526
import org.springframework.beans.factory.support.AbstractBeanDefinition;
2627
import org.springframework.core.annotation.AliasFor;
2728

@@ -202,6 +203,7 @@
202203
* @author Chris Beams
203204
* @author Juergen Hoeller
204205
* @author Sam Brannen
206+
* @author Yanming Zhou
205207
* @since 3.0
206208
* @see Configuration
207209
* @see Scope
@@ -242,6 +244,10 @@
242244
* Is this bean a candidate for getting autowired into some other bean at all?
243245
* <p>Default is {@code true}; set this to {@code false} for internal delegates
244246
* that are not meant to get in the way of beans of the same type in other places.
247+
* <p>NOTE: if this is set to {@code false}, bean is excluded when autowiring
248+
* arrays, collections, maps, or ObjectProvider streams, use
249+
* {@link ConfigurableListableBeanFactory#getBeansOfType(Class)}
250+
* if you want to get all beans of the same type.
245251
* @since 5.1
246252
* @see #defaultCandidate()
247253
*/
@@ -253,6 +259,10 @@
253259
* <p>Default is {@code true}; set this to {@code false} for restricted delegates
254260
* that are supposed to be injectable in certain areas but are not meant to get
255261
* in the way of beans of the same type in other places.
262+
* <p>NOTE: if this is set to {@code false}, bean is excluded when autowiring
263+
* arrays, collections, maps, or ObjectProvider streams, use
264+
* {@link ConfigurableListableBeanFactory#getBeansOfType(Class)}
265+
* if you want to get all beans of the same type.
256266
* <p>This is a variation of {@link #autowireCandidate()} which does not disable
257267
* injection in general, just enforces an additional indication such as a qualifier.
258268
* @since 6.2

0 commit comments

Comments
 (0)