Only one constructor (at max) of any given bean class may carry this
annotation with the 'required' parameter set to true, indicating the
constructor to autowire when used as a Spring bean. If multiple
non-required constructors carry the annotation, they will be
considered as candidates for autowiring. The constructor with the
greatest number of dependencies that can be satisfied by matching
beans in the Spring container will be chosen. If none of the
candidates can be satisfied, then a default constructor (if present)
will be used. An annotated constructor does not have to be public.
田里
Fields are injected right after construction of a bean, before any
config methods are invoked. Such a config field does not have to be
public.
方法
Config methods may have an arbitrary name and any number of arguments;
each of those arguments will be autowired with a matching bean in the
Spring container. Bean property setter methods are effectively just a
special case of such a general config method. Config methods do not
have to be public.
# 1 楼答案
通过}
@Autowired
的自动连线是由BeanPostProcessor
实现执行的,特别是^{这个
BeanPostProcessor
处理每个bean,将扫描其类(和超类)中的任何@Autowired
注释,并根据注释是什么(构造函数、字段或方法),采取适当的操作对于建设者
田里
方法
所有这些都是通过反思来完成的
进一步阅读: