xml的定义有两种约束方式:dtd、xsd
spring采用xsd约束xml的格式,在xml的头部(beans 的属性)中引入命名空间和xsd文件;Spring提供了可扩展Schema的支持,如Dubbo就有自己的schema 文件。
xmlns用于定义命名空间,xmlns=""为默认命名空间;
xmlns:xx可以自定义命名空间,xx叫命名空间的前缀,xml文件中的元素,以xx开头表示使用该命名空间对应的xsd文件来约束配置
xsi:schemalocation用于指定命名空间和xsd文件的对应关系;xsi:schemalocation实际上是xsi 命名空间的一个属性。
使用spring至少应包含xmlns/xmlns:xsi命名空间及对应的xsd文件,其他的使用的功能添加
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
参考文档:
https://www.cnblogs.com/zhao1949/p/5652167.html
https://www.cnblogs.com/coreyjk/p/6408638.html
spring容器启动时,会加载指定的配置文件,会读取到spring默认的schema和其他的schema(如dubbo自定义的schema),每一个schema都有对应的NamespaceHandler,NamespaceHandler里面通过BeanDefinitionParser来解析配置信息并转化为需要加载的bean对象 。
通过META-INF/spring.handlers的扩展点来指定xml-namespace与NameSpaceHandler的对应关系;
通过META-INF/spring.schemas来指定xsi-loacation中定义的xsd文件在项目中的路径。
参考文档:
https://blog.csdn.net/u010648555/article/details/78050158
spring schema扩展具体实现参考:
https://blog.csdn.net/cutesource/article/details/5864562