spring---------配置文件的命名空间

两种格式的配置文件:

DTD和Schema区别:http://www.cnblogs.com/zhaozhan/archive/2010/01/04/1639194.html

 

1 <?xml version="1.0" encoding="UTF-8"?>
2 <beans xmlns="http://www.springframework.org/schema/beans"  <!--默认命名空间:表示未使用其他命名空间的所有标签的默认命名空间-->
3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   <!--xsi标准命名空间,用于指定义自定义命名空间的schema文件,声明后就可以使用 schemaLocation 属性了-->
4     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">  <!--此处可以不配置,可以用来引用schema在本地的副本-->
5    
6     
7 
8 </beans>

为每个命名空间指定了对应的Schema文档的时候,定义的语法为:

  “全称命名空间1  空格  全称命名空间1对应的Schema文件空格”

其他命名空间与

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

同一级别下配置即可

  • util

util标签用来处理公用、实用的配置问题,例如配置集合、常量及诸如此类的东西

xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation中需要定义
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
  • jee

jee标签用来处理javaee标准相关的问题,例如查询一个jndi对象以及定义一个ejb的引用等

xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation中需要定义
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
  • lang 

 

lang用来将那些已经被定义在一些动态语言(例如Jruby和Groovy)中的对象作为beans中的对象存放到spring容器中

xmlns:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation中需要定义
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
  • jms 

 

xmlns:jms="http://www.springframework.org/schema/jms"

 

http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd
  • tx (transaction) 

使用时建议配合aop

xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"

 

http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd

 

  • aop 

 

xmlns:aop="http://www.springframework.org/schema/aop"

 

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
  • context 

 

xmlns:context="http://www.springframework.org/schema/context"

 

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  • jdbc 

 

xmlns:jdbc="http://www.springframework.org/schema/jdbc"

 

http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
  • cache 

 

xmlns:jdbc="http://www.springframework.org/schema/cache"

 

http://www.springframework.org/schema/cache http://www.springframework.org/schema/jdbc/spring-cache.xsd

 

  • 完整的一个配置文件头如下

<?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:cache="http://www.springframework.org/schema/cache"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:jms="http://www.springframework.org/schema/jms" xmlns:lang="http://www.springframework.org/schema/lang"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:oxm="http://www.springframework.org/schema/oxm"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd    
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd    
        http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.1.xsd    
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd    
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd    
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.1.xsd    
        http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-4.1.xsd    
        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-4.1.xsd    
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd    
        http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-4.1.xsd    
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd    
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd    
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd">



</beans>      

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。