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
- context:component-scan標籤的use-default-filters屬性的作用以及原理分析ContextFilter
- 【spring原始碼學習】spring的IOC容器之自定義xml配置標籤擴充套件namspaceHandler向IOC容器中註冊beanSpring原始碼XML套件Bean
- Mybatis應用手冊MyBatis
- 【Spring】重構--手寫Spring核心邏輯(三)實現IOC/DI(context包)SpringContext
- spring原始碼深度解析— IOC 之 屬性填充Spring原始碼
- XML屬性XML
- Spring 系列(四):我們來聊聊<context:component-scan/>SpringContext
- spring原始碼解析之IOC容器(四)——屬性注入Spring原始碼
- 死磕Spring之IoC篇 - Bean 的屬性填充階段SpringBean
- <context:component-scan> 標籤Context
- XML 屬性概述XML
- Spring-Context之三:使用XML和Groovy DSL配置BeanSpringContextXMLBean
- 面試:spring ioc實現原理面試Spring
- Spring IoC Context啟動過程解析SpringContext
- Spring實現IOC容器的兩種實現方式Spring
- 《Spring原始碼分析》IOC的實現Spring原始碼
- 4. Spring對IoC的實現Spring
- Spring IOC容器【p名稱空間注入屬性值 】Spring
- Spring(三)屬性配置細節Spring
- <context:annotation-config/>、<context:component-scan/>Context
- Linux iptables應用手冊Linux
- Android XML 屬性AndroidXML
- Spring(三):IoC容器裝配Bean(xml配置方式和註解方式)SpringBeanXML
- Spring IOC容器實現機制Spring
- spring IOC容器實現探討Spring
- 自己簡單實現Spring的IOC原理Spring
- Spring IOC容器的設計與實現Spring
- Spring基礎使用(一)--------IOC、Bean的XML方式SpringBeanXML
- Spring系列:基於XML的方式構建IOCSpringXML
- spring應用手冊-AOP(註解)-(20)-切面釋出-前置通知Spring
- Rational ClearQuest 安裝、配置、使用手冊
- Spring Cloud 覆寫遠端的配置屬性SpringCloud
- less語法實用手冊
- Spring IoC容器與應用上下文的設計與實現Spring