Spring 自定义命名空间 xsd

编写这两个文件
META-INF/spring.handlers
META-INF/spring.schemas

写法可以参照spring 那包下那两个文件,

Handler 继承  org.springframework.beans.factory.xml.NamespaceHandlerSupport

覆盖父类的 init(),

方法里调用
void org.springframework.beans.factory.xml.NamespaceHandlerSupport.registerBeanDefinitionParser(String elementName, BeanDefinitionParser parser)

----------------------------------------------------------------------------------
下面是 Spring 加载原理
可以看到那两个文件都是 properties 格式的。

spring Application context 启动时执行:
void org.springframework.context.support.AbstractApplicationContext.refresh() 


直到调用

String org.springframework.beans.factory.xml.PluggableSchemaResolver.getSchemaMapping(String systemId)


通过
Enumeration<URL> = ClassLoader.getResources(String name)  


获取对应文件的 URL ,然后就可以获取 Input 流,读取这两个 properties  文件。

猜你喜欢

转载自id-alex.iteye.com/blog/1872987
xsd
今日推荐