Skip to content

Commit e1080f8

Browse files
committed
Polish Javadoc for @Autowired
1 parent 3a9262c commit e1080f8

File tree

1 file changed

+19
-10
lines changed
  • spring-beans/src/main/java/org/springframework/beans/factory/annotation

1 file changed

+19
-10
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/annotation/Autowired.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,10 +23,11 @@
2323
import java.lang.annotation.Target;
2424

2525
/**
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
2727
* Spring's dependency injection facilities. This is an alternative to the JSR-330
2828
* {@link javax.inject.Inject} annotation, adding required-vs-optional semantics.
2929
*
30+
* <h3>Autowired Constructors</h3>
3031
* <p>Only one constructor (at max) of any given bean class may declare this annotation
3132
* with the 'required' parameter set to {@code true}, indicating <i>the</i> constructor
3233
* to autowire when used as a Spring bean. If multiple <i>non-required</i> constructors
@@ -37,28 +38,35 @@
3738
* If a class only declares a single constructor to begin with, it will always be used,
3839
* even if not annotated. An annotated constructor does not have to be public.
3940
*
41+
* <h3>Autowired Fields</h3>
4042
* <p>Fields are injected right after construction of a bean, before any config methods
4143
* are invoked. Such a config field does not have to be public.
4244
*
45+
* <h3>Autowired Methods</h3>
4346
* <p>Config methods may have an arbitrary name and any number of arguments; each of
4447
* those arguments will be autowired with a matching bean in the Spring container.
4548
* Bean property setter methods are effectively just a special case of such a general
4649
* config method. Such config methods do not have to be public.
4750
*
51+
* <h3>Multiple Arguments and 'required' Semantics</h3>
4852
* <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
5054
* {@link java.util.Optional} or, as of Spring Framework 5.0, also as {@code @Nullable}
5155
* or a not-null parameter type in Kotlin, overriding the base required semantics.
5256
*
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
6067
* {@code Collection} or {@code Map} itself, getting injected as such.
6168
*
69+
* <h3>Not supported in {@code BeanPostProcessor} or {@code BeanFactoryPostProcessor}</h3>
6270
* <p>Note that actual injection is performed through a
6371
* {@link org.springframework.beans.factory.config.BeanPostProcessor
6472
* BeanPostProcessor} which in turn means that you <em>cannot</em>
@@ -71,6 +79,7 @@
7179
*
7280
* @author Juergen Hoeller
7381
* @author Mark Fisher
82+
* @author Sam Brannen
7483
* @since 2.5
7584
* @see AutowiredAnnotationBeanPostProcessor
7685
* @see Qualifier

0 commit comments

Comments
 (0)