首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

spring 源码 窥视2

2012-09-07 
spring 源码 窥视二前几天一直在运行 org.springframework.beans-3.0.4.RELEASE 自带的Test Projects. 运

spring 源码 窥视二
前几天一直在运行 org.springframework.beans-3.0.4.RELEASE 自带的Test Projects. 运行很失望,因为很多都运行不起来 所以在想是粗粗的把源码读一遍呢还是锱铢必较,把每个小点都搞清楚。我选择了后者
今天终于小有收获。

成功的运行了 SimplePropertyNamespaceHandlerTests.java
50%明白了spring如何解析spring配置文件的,这50是spring如何验证配置的正确性。
看里面component-config.xml的例子

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:foo="http://www.foo.com/schema/component"
      xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.foo.com/schema/component http://www.foo.com/schema/component/component.xsd">

   <foo:component id="bionic-family" name="Bionic-1">
      <foo:component name="Mother-1">
      <foo:component name="Karate-1"/>
  <foo:component name="Sport-1"/>
      </foo:component>
      <foo:component name="Rock-1"/>
   </foo:component>

</beans>

整个过程应该是这样,查看schema中的 "xsi:schemaLocation" 前面是域名,后面是具体文件名。然后PluggableSchemaResolver会根据"META-INF/spring.schemas"里面的值。通过前面的文件名对应properties的值找到具体本地的xsd文件,然后进行resolve

通过这三个类
PluggableSchemaResolver  继承 EntityResolver   通过一个properties文件把url映射为本地文件
DelegatingEntityResolver 继承 EntityResolver
ResourceEntityResolver   继承 DelegatingEntityResolver
原来是有一个xsd文件,(恕我小白,一直被蒙在鼓里)。

热点排行