---
title: "spring初始化"
author: "周星星童鞋2"
date: "2019-09-15T15:14:30Z"
tags: []
categories: ["企业架构"]
slug: "spring"
draft: false
lastmod: "2019-09-15T23:22:27Z"
id: 2458752
url: "https://632928374.iteye.com/blog/2458752"
---

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属性设置器方法。因此，如果注入目标是构造函数或多参数方法，请使用限定符。