Spring配置文件命名空间

来源:互联网 发布:海康网络摄像机重量 编辑:程序博客网 时间:2024/06/05 15:59

 

 xmlns

xml namespace的缩写,也就是XML命名空间,xmlns 属性可以在文档中定义一个或多个可供选择的命名空间

 

<?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:tx="http://www.springframework.org/schema/tx"       xmlns:aop="http://www.springframework.org/schema/aop"       xsi:schemaLocation="http://www.springframework.org/schema/beans           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd           http://www.springframework.org/schema/aop           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd           http://www.springframework.org/schema/context           http://www.springframework.org/schema/context/spring-context2.5.xsd           http://www.springframework.org/schema/tx            http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"><aop:aspectj-autoproxy/><!--使用注解的方式AOP注入--><bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator"/><bean id="person" class="hb.dao.imp.PersonImp"/><bean id="aop" class="hb.aop.Aop"/></beans>

 命名空间的内容可以从对应的jar包中找到,这里以AOP为例子说明,如图

 

 

打开spring.schemas文件,可以查看到对应命名空间内容,然后输入到配置文件中(这里要保证版本对应)

 

http\://www.springframework.org/schema/aop/spring-aop-2.0.xsd=org/springframework/aop/config/spring-aop-2.0.xsdhttp\://www.springframework.org/schema/aop/spring-aop-2.5.xsd=org/springframework/aop/config/spring-aop-2.5.xsdhttp\://www.springframework.org/schema/aop/spring-aop.xsd=org/springframework/aop/config/spring-aop-2.5.xsd

 

在配置文件中的xsi:schemaLocation标签的内容有顺序,例如

 

 

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

 

必须保证http://www.springframework.org/schema/aop

在 http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
前面,否则不会正确的解析