spring初始化
6.8 容器扩展点
RequiredAnnotationBeanPostProcessor 作用是:如果一个被标为@Required的bean的setter方法,那么这个bean就要有这个属性注入,如果不想对某个bean进行检测,可以将此bean的bean definition的org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor.skipRequiredCheck属性设置为false。
PropertyPlaceholderConfigurer
FactoryBean -----
(隐式注册的后处理器包括autowiredannotationbeanpostprocessor、commonannotationbeanpostprocessor、persistenceannotationbeanpostprocessor以及前面提到的requiredannotationbeanpostprocessor。)
如果您打算按名称来表示注释驱动的注入,请不要主要使用@autowired,即使技术上能够通过@qualifier值引用bean名称。相反,请使用jsr-250@resource注释,该注释在语义上定义为通过其唯一名称标识特定的目标组件,声明的类型与匹配进程无关。
rú如 guǒ果 nín您 dǎ打 suàn算 àn按 míng名 chēng称 lái来 biǎo表 shì示 zhù注 shì释 qū驱 dòng动 de的 zhù注 rù入 , qǐng请 bù不 yào要 zhǔ主 yào要 shǐ使 yòng用 @ a u t o w i r e d , jí即 shǐ使 jì技 shù术 shàng上 néng能 gòu够 tōng通 guò过 @ q u a l i f i e r zhí值 yǐn引 yòng用 b e a n míng名 chēng称 。 xiāng相 fǎn反 , qǐng请 shǐ使 yòng用 j s r - 2 5 0 @ r e s o u r c e zhù注 shì释 , gāi该 zhù注 shì释 zài在 yǔ语 yì义 shàng上 dìng定 yì义 wéi为 tōng通 guò过 qí其 wéi唯 yī一 míng名 chēng称 biāo标 shí识 tè特 dìng定 de的 mù目 biāo标 zǔ组 jiàn件 , shēng声 míng明 de的 lèi类 xíng型 yǔ与 pǐ匹 pèi配 jìn进 chéng程 wú无 guān关 。
As a specific consequence of this semantic difference, beans that are themselves defined as a collection or map type cannot be injected through @Autowired, because type matching is not properly applicable to them. Use @Resource for such beans, referring to the specific collection or map bean by unique name.
这种语义差异的一个具体结果是,本身被定义为集合或映射类型的bean不能通过@autowired注入,因为类型匹配不适合它们。对此类bean使用@resource,通过唯一的名称引用特定的集合或映射bean。
zhè这 zhǒng种 yǔ语 yì义 chā差 yì异 de的 yī一 gè个 jù具 tǐ体 jié结 guǒ果 shì是 , běn本 shēn身 bèi被 dìng定 yì义 wéi为 jí集 hé合 huò或 yìng映 shè射 lèi类 xíng型 de的 b e a n bù不 néng能 tōng通 guò过 @ a u t o w i r e d zhù注 rù入 , yīn因 wèi为 lèi类 xíng型 pǐ匹 pèi配 bù不 shì适 hé合 tā它 men们 。 duì对 cǐ此 lèi类 b e a n shǐ使 yòng用 @ r e s o u r c e , tōng通 guò过 wéi唯 yī一 de的 míng名 chēng称 yǐn引 yòng用 tè特 dìng定 de的 jí集 hé合 huò或 yìng映 shè射 b e a n 。
@Autowired applies to fields, constructors, and multi-argument methods, allowing for narrowing through qualifier annotations at the parameter level. By contrast, @Resource is supported only for fields and bean property setter methods with a single argument. As a consequence, stick with qualifiers if your injection target is a constructor or a multi-argument method.
@autowired应用于字段、构造函数和多参数方法,允许在参数级别缩小限定符注释的范围。相比之下,@resource只支持具有单个参数的字段和bean属性设置器方法。因此,如果注入目标是构造函数或多参数方法,请使用限定符。