【2】spring4.0.5初始化之listener
//NamespaceHandlerSupport implements NamespaceHandler
2.1 findParserForElement(element, parserContext).parse(element, parserContext)//找到不同的解析器去處理解析到的內容// NamespaceHandlerSupportBeanDefinitionParser parser = this.parsers.get(localName);
//BeanDefinitionParser 這個是解析器的介面
//判斷是否有註解
if (metadata == null || !metadata.isAnnotated(Conditional.class.getName())) {
return false;
}
AnnotationMetadataReadingVisitor extends ClassMetadataReadingVisitor implements AnnotationMetadata
//AnnotationMetadataReadingVisitor 類存放解析之後的類容
//將檔案放到快取的CachingMetadataReaderFactory裡面,同時將類的註解資訊放到
AnnotationMetadataReadingVisitor visitor = new AnnotationMetadataReadingVisitor(classLoader);
private MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(this.resourcePatternResolver);
new SimpleMetadataReader(resource, this.resourceLoader.getClassLoader())
public MetadataReader getMetadataReader(Resource resource) throws IOException {
if (getCacheLimit() <= 0) {
return super.getMetadataReader(resource);
}
synchronized (this.metadataReaderCache) {
MetadataReader metadataReader = this.metadataReaderCache.get(resource);
if (metadataReader == null) {
metadataReader = super.getMetadataReader(resource);
this.metadataReaderCache.put(resource, metadataReader);
}
return metadataReader;
}
}
CachingMetadataReaderFactory extends SimpleMetadataReaderFactory
readClass(final InputStream is, boolean close) //ClassReader //讀取類的資訊
//AnnotationMetadataReadingVisitor extends ClassMetadataReadingVisitor implements AnnotationMetadata
public AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
String className = Type.getType(desc).getClassName();
this.annotationSet.add(className);
return new AnnotationAttributesReadingVisitor(className, this.attributesMap, this.metaAnnotationMap, this.classLoader);
}
根據原始檔的 SourceFile LoginController.java +Lorg/springframework/stereotype/Controller; ! 去判斷註解了那些類
//PluggableSchemaResolver 獲取所有schem 放到properties裡面
getSchemaMappings(){
Properties mappings =
PropertiesLoaderUtils.loadAllProperties(this.schemaMappingsLocation, this.classLoader);
}