|
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.
|
|
23 | 23 | import java.lang.annotation.Target;
|
24 | 24 |
|
25 | 25 | /**
|
26 |
| - * Marks a constructor, field, setter method or config method as to be autowired by |
| 26 | + * Marks a constructor, field, setter method, or config method as to be autowired by |
27 | 27 | * Spring's dependency injection facilities. This is an alternative to the JSR-330
|
28 | 28 | * {@link javax.inject.Inject} annotation, adding required-vs-optional semantics.
|
29 | 29 | *
|
| 30 | + * <h3>Autowired Constructors</h3> |
30 | 31 | * <p>Only one constructor (at max) of any given bean class may declare this annotation
|
31 | 32 | * with the 'required' parameter set to {@code true}, indicating <i>the</i> constructor
|
32 | 33 | * to autowire when used as a Spring bean. If multiple <i>non-required</i> constructors
|
|
37 | 38 | * If a class only declares a single constructor to begin with, it will always be used,
|
38 | 39 | * even if not annotated. An annotated constructor does not have to be public.
|
39 | 40 | *
|
| 41 | + * <h3>Autowired Fields</h3> |
40 | 42 | * <p>Fields are injected right after construction of a bean, before any config methods
|
41 | 43 | * are invoked. Such a config field does not have to be public.
|
42 | 44 | *
|
| 45 | + * <h3>Autowired Methods</h3> |
43 | 46 | * <p>Config methods may have an arbitrary name and any number of arguments; each of
|
44 | 47 | * those arguments will be autowired with a matching bean in the Spring container.
|
45 | 48 | * Bean property setter methods are effectively just a special case of such a general
|
46 | 49 | * config method. Such config methods do not have to be public.
|
47 | 50 | *
|
| 51 | + * <h3>Multiple Arguments and 'required' Semantics</h3> |
48 | 52 | * <p>In the case of a multi-arg constructor or method, the 'required' parameter is
|
49 |
| - * applicable to all arguments. Individual parameters may be declared as Java-8-style |
| 53 | + * applicable to all arguments. Individual parameters may be declared as Java-8 style |
50 | 54 | * {@link java.util.Optional} or, as of Spring Framework 5.0, also as {@code @Nullable}
|
51 | 55 | * or a not-null parameter type in Kotlin, overriding the base required semantics.
|
52 | 56 | *
|
53 |
| - * <p>In case of a {@link java.util.Collection} or {@link java.util.Map} dependency type, |
54 |
| - * the container autowires all beans matching the declared value type. For such purposes, |
55 |
| - * the map keys must be declared as type String which will be resolved to the corresponding |
56 |
| - * bean names. Such a container-provided collection will be ordered, taking into account |
57 |
| - * {@link org.springframework.core.Ordered}/{@link org.springframework.core.annotation.Order} |
58 |
| - * values of the target components, otherwise following their registration order in the |
59 |
| - * container. Alternatively, a single matching target bean may also be a generally typed |
| 57 | + * <h3>Autowiring Arrays, Collections, and Maps</h3> |
| 58 | + * <p>In case of an array, {@link java.util.Collection}, or {@link java.util.Map} |
| 59 | + * dependency type, the container autowires all beans matching the declared value |
| 60 | + * type. For such purposes, the map keys must be declared as type {@code String} |
| 61 | + * which will be resolved to the corresponding bean names. Such a container-provided |
| 62 | + * collection will be ordered, taking into account |
| 63 | + * {@link org.springframework.core.Ordered Ordered} and |
| 64 | + * {@link org.springframework.core.annotation.Order @Order} values of the target |
| 65 | + * components, otherwise following their registration order in the container. |
| 66 | + * Alternatively, a single matching target bean may also be a generally typed |
60 | 67 | * {@code Collection} or {@code Map} itself, getting injected as such.
|
61 | 68 | *
|
| 69 | + * <h3>Not supported in {@code BeanPostProcessor} or {@code BeanFactoryPostProcessor}</h3> |
62 | 70 | * <p>Note that actual injection is performed through a
|
63 | 71 | * {@link org.springframework.beans.factory.config.BeanPostProcessor
|
64 | 72 | * BeanPostProcessor} which in turn means that you <em>cannot</em>
|
|
71 | 79 | *
|
72 | 80 | * @author Juergen Hoeller
|
73 | 81 | * @author Mark Fisher
|
| 82 | + * @author Sam Brannen |
74 | 83 | * @since 2.5
|
75 | 84 | * @see AutowiredAnnotationBeanPostProcessor
|
76 | 85 | * @see Qualifier
|
|
0 commit comments