在分析的时候(三)中遇到一些问题,直接让我怀疑人生。可是通过多方面查找资料,发如今IDEA环境中启用了enable toString后,就会隐式执行toString方法(可是调试时,不会进toString方法)因此我猜测应该是IDEA工具编译器的问题,在Eclipse中就不会存在这样的问题。java
public NamespaceHandler resolve(String namespaceUri) { //获取当前系统全部的META-INF/spring.handlers文件(其底层经过Enumeration urls = classLoaderToUse != null?classLoaderToUse.getResources(resourceName):ClassLoader.getSystemResources(resourceName);来获取资源的) //返回的map格式例如:http://www.springframework.org/schema/aop=org.springframework.aop.config.AopNamespaceHandler //这里就根据命名空间key,来获取对应该命名空间的处理器(Handler)并实例化这个处理器 Map handlerMappings = this.getHandlerMappings(); Object handlerOrClassName = handlerMappings.get(namespaceUri); if(handlerOrClassName == null) { return null; } else if(handlerOrClassName instanceof NamespaceHandler) { return (NamespaceHandler)handlerOrClassName; } else { String className = (String)handlerOrClassName; try { Class err = ClassUtils.forName(className, this.classLoader); if(!NamespaceHandler.class.isAssignableFrom(err)) { throw new FatalBeanException("Class [" + className + "] for namespace [" + namespaceUri + "] does not implement the [" + NamespaceHandler.class.getName() + "] interface"); } else { //完成处理器的建立并调用了init方法初始化 NamespaceHandler namespaceHandler = (NamespaceHandler)BeanUtils.instantiateClass(err); namespaceHandler.init(); handlerMappings.put(namespaceUri, namespaceHandler); return namespaceHandler; } } catch (ClassNotFoundException var7) { throw new FatalBeanException("NamespaceHandler class [" + className + "] for namespace [" + namespaceUri + "] not found", var7); } catch (LinkageError var8) { throw new FatalBeanException("Invalid NamespaceHandler class [" + className + "] for namespace [" + namespaceUri + "]: problem with handler class file or dependent class", var8); } } }
public BeanDefinition parseCustomElement(Element ele, BeanDefinition containingBd) { String namespaceUri = this.getNamespaceURI(ele); //在上面的方法中具体讲解了this.readerContext.getNamespaceHandlerResolver().resolve(namespaceUri)干了些什么事情?(就是完成了根据命名空间完成了该命名空间对应的处理器初始化等操做) NamespaceHandler handler = this.readerContext.getNamespaceHandlerResolver().resolve(namespaceUri); if(handler == null) { this.error("Unable to locate Spring NamespaceHandler for XML schema namespace [" + namespaceUri + "]", ele); return null; } else { //这里就根据实际的处理器进行处理。(例如apo,tx,context,task) return handler.parse(ele, new ParserContext(this.readerContext, this, containingBd)); } } 具体命名空间以及处理器的对应关系 http://www.springframework.org/schema/p value:org.springframework.beans.factory.xml.SimplePropertyNamespaceHandler http://www.springframework.org/schema/util value:org.springframework.beans.factory.xml.UtilNamespaceHandler http://www.springframework.org/schema/jee value:org.springframework.ejb.config.JeeNamespaceHandler http://www.springframework.org/schema/aop value:org.springframework.aop.config.AopNamespaceHandler http://www.springframework.org/schema/redis value:org.springframework.data.redis.config.RedisNamespaceHandler http://www.springframework.org/schema/cache value:org.springframework.cache.config.CacheNamespaceHandler http://www.springframework.org/schema/c value:org.springframework.beans.factory.xml.SimpleConstructorNamespaceHandler http://www.springframework.org/schema/tx value:org.springframework.transaction.config.TxNamespaceHandler http://www.springframework.org/schema/lang value:org.springframework.scripting.config.LangNamespaceHandler http://www.springframework.org/schema/task value:org.springframework.scheduling.config.TaskNamespaceHandler http://www.springframework.org/schema/context value:org.springframework.context.config.ContextNamespaceHandler //经过这里咱们发现spring确实太强大啦,各个模块都是面向接口编程,完成的松耦合。 //【注】若是要具体分析这些处理器背后到底作了一些什么事情,能够在细化研究分析
到此为止,关于spring里面的自定义标签的BeanDefinition定义就处理完毕了redis
下一节须要分析parseDefaultElement默认节点处理例如spring
<bean name="ApplicationContextUtil;zxsApplicationUtil" class="com.wolf.util.ApplicationContextUtil"/>