Spring的XML配置引入XML Schema语法简化配置

来源:互联网 发布:mac diva dare you试色 编辑:程序博客网 时间:2024/06/05 18:42

在Spring1.x系列中,bean的配置文件使用DTD,没有namespace的分隔。

<? xml version = " 1.0 "  encoding = " UTF-8 " ?>
<! DOCTYPE beans PUBLIC  " -//SPRING//DTD BEAN//EN "
        
" http://www.springframework.org/dtd/spring-beans.dtd " >

< beans >
    
</ beans >

2.0的一个非常大的改进是引入了XML Schema的namespace,因而可以将bean的配置文件做大幅度的简化。

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

</ beans >

这些简化包括了对bean属性的各种简化,AOP配置的简化,事务配置的简化,JNDI配置的简化等方面。

 
原创粉丝点击