Spring 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"   
    <!--xsi标准命名空间,用于指定自定义命名空间的schema文件,声明后就可以使用schemaLocation 属性了-->

   xsi:schemaLocation="http://www.springframework.org/schema/beans         
        http://www.springframework.org/schema/beans/spring-beans.xsd">  
    <!--此处可以不配置,可以用来引用schema在本地的副本-->
   
</beans>

 

  再看一个:

<?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:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/spring-aop.xsd
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="concert"/>
    <aop:aspectj-autoproxy/>
    <bean class="concert.Audience"/>

</beans>

   以xmlns开头的行,都是在声明各个配置元素,例如xsi、context、aop,以便配置中可以使用这些配置元素;

  此外,还需要告诉xml解析器,aop这个命名空间是在哪里定义的,以便解析器能够验证当前文件中aop:开头的元素是否符合aop命名空间的标准。

  这样解析器在解释aop:命名空间的时候,会参考spring-aop.xsd这个文件来检验<aop:aspectj-autoproxy/>是否合格。

  

posted @ 2018-01-29 05:17  爆炸的果核  阅读(729)  评论(0编辑  收藏  举报