spring的shema文件怎么读取
spring的shema文件如何读取
spring 的配置文件的beans 里面有属性头部如下:
<?xml version="1.0" encoding="UTF-8"?> <!--suppress ALL --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
xmlns:xxx 就是定义一个 xxx前缀命名空间。然后下面可以如此定义 <xxx:apple .../> ,当然apple 是在shema文件中声明好的。shema 文件在哪里找?就是后面的 xsi:shemaLocation 里,其里面的值是成对出现的。
key 是前头通过 xmlns:xxx 定义时的值,如上面的“http://www.springframework.org/schema/aop” ,value 是一个url地址(当然其实也可以是非url字符串),那么spring是如何读取这个url对应的shema文件的呢?spring会扫描所有的jar文件,查找 jar文件里/META-INF/ 下面的 spring.handlers 和 spring.shemas 2个文件。
spring.handlers 文件是定义 使用哪个class类来解析该段 xml内容 ,形如:
http\://www.springframework.org/schema/aop=org.springframework.aop.config.AopNamespaceHandler
spring.shemas 文件里定义的是 schema文件的真实地址(基于classPath的)
http\://www.springframework.org/schema/aop/spring-aop-2.0.xsd=org/springframework/aop/config/spring-aop-2.0.xsd http\://www.springframework.org/schema/aop/spring-aop-2.5.xsd=org/springframework/aop/config/spring-aop-2.5.xsd http\://www.springframework.org/schema/aop/spring-aop-3.0.xsd=org/springframework/aop/config/spring-aop-3.0.xsd http\://www.springframework.org/schema/aop/spring-aop.xsd=org/springframework/aop/config/spring-aop-3.0.xsd
故,其实在断网的情况下,spring肯定也是可以正常启动的。