spring應用手冊-IOC(XML配置實現)-(36)-context:component-scan的scope-resolver屬性
戴著假髮的程式設計師出品
context:component-scan的scope-resolver屬性
spring應用手冊(第一部分)
注意這個屬性scope-resolver和scoped-proxy是互斥的。
這個屬性跟name-generator有點類似,它是基於介面ScopeMetadataResolver的,實現resolveScopeMetadata方法,目的是為了將@Scope(value="",proxyMode=ScopedProxyMode.NO,scopeName="")的配置解析成為一個ScopeMetadata物件,Spring這裡也提供了兩個實現,我們一起看下。首先是org.springframework.context.annotation.AnnotationScopeMetadataResolver中,
public ScopeMetadata resolveScopeMetadata(BeanDefinition definition) {
ScopeMetadata metadata = new ScopeMetadata();
if (definition instanceof AnnotatedBeanDefinition) {
AnnotatedBeanDefinition annDef = (AnnotatedBeanDefinition) definition;
AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(annDef.getMetadata(), this.scopeAnnotationType);
if (attributes != null) {
metadata.setScopeName(attributes.getAliasedString("value", this.scopeAnnotationType, definition.getSource()));
ScopedProxyMode proxyMode = attributes.getEnum("proxyMode");
if (proxyMode == null || proxyMode == ScopedProxyMode.DEFAULT) {
proxyMode = this.defaultProxyMode;
}
metadata.setScopedProxyMode(proxyMode);
}
}
return metadata;
}
org.springframework.context.annotation.Jsr330ScopeMetadataResolver中的實現
public ScopeMetadata resolveScopeMetadata(BeanDefinition definition) {
ScopeMetadata metadata = new ScopeMetadata();
metadata.setScopeName(BeanDefinition.SCOPE_PROTOTYPE);
if (definition instanceof AnnotatedBeanDefinition) {
AnnotatedBeanDefinition annDef = (AnnotatedBeanDefinition) definition;
Set<String> annTypes = annDef.getMetadata().getAnnotationTypes();
String found = null;
for (String annType : annTypes) {
Set<String> metaAnns = annDef.getMetadata().getMetaAnnotationTypes(annType);
if (metaAnns.contains("javax.inject.Scope")) {
if (found != null) {
throw new IllegalStateException("Found ambiguous scope annotations on bean class [" +
definition.getBeanClassName() + "]: " + found + ", " + annType);
}
found = annType;
String scopeName = resolveScopeName(annType);
if (scopeName == null) {
throw new IllegalStateException(
"Unsupported scope annotation - not mapped onto Spring scope name: " + annType);
}
metadata.setScopeName(scopeName);
}
}
}
return metadata;
}
相關文章
- spring應用手冊-IOC(XML配置實現)-(35)-context:component-scan的scoped-proxy屬性SpringXMLContext
- spring應用手冊-IOC(XML配置實現)-(26)-注入set集合SpringXML
- Spring IOC XML配置SpringXML
- context:component-scan屬性介紹,SSM的bean被掃描兩次問題ContextSSMBean
- Spring 系列(四):我們來聊聊<context:component-scan/>SpringContext
- 【Spring】重構--手寫Spring核心邏輯(三)實現IOC/DI(context包)SpringContext
- <context:component-scan> 標籤Context
- Mybatis應用手冊MyBatis
- spring原始碼深度解析— IOC 之 屬性填充Spring原始碼
- Android XML 屬性AndroidXML
- XML 屬性概述XML
- spring原始碼解析之IOC容器(四)——屬性注入Spring原始碼
- 死磕Spring之IoC篇 - Bean 的屬性填充階段SpringBean
- Spring(三)屬性配置細節Spring
- 4. Spring對IoC的實現Spring
- 《Spring原始碼分析》IOC的實現Spring原始碼
- Spring實現IOC容器的兩種實現方式Spring
- Spring系列:基於XML的方式構建IOCSpringXML
- Spring基礎使用(一)--------IOC、Bean的XML方式SpringBeanXML
- spring應用手冊-AOP(註解)-(20)-切面釋出-前置通知Spring
- 面試:spring ioc實現原理面試Spring
- Spring IOC容器實現機制Spring
- Spring IOC容器的設計與實現Spring
- Rational ClearQuest 安裝、配置、使用手冊
- annotation之context:annotation-config與 context:component-scan的區別與聯絡Context
- Spring AOP基於xml的方式實現SpringXML
- Spring 常用的註解以及對應 XML 配置詳解SpringXML
- Spring IoC容器與應用上下文的設計與實現Spring
- 系列文章:spring的xml配置是如何對應註解配置的之配置介紹SpringXML
- XML DOM – 屬性和方法概述XML
- Spring基於註解的IoC配置Spring
- SpringBoot中根據屬性動態註冊Spring BeanSpring BootBean
- Spring入門配置(一) - IOCSpring
- 原來 spring.xml 配置的 destroy-method 需要用到向虛擬機器註冊鉤子來實現!SpringXML虛擬機
- Spring系列之IOC的原理及手動實現Spring
- Spring裡component-scan的工作原理Spring
- Spring框架系列(7) - Spring IOC實現原理詳解之IOC初始化流程Spring框架
- Spring的BeanFactoryPostProcessor中屬性SpringBean