您的位置:首页 > 编程语言 > Java开发

Spring配置文件命名空间

2013-12-04 10:04 337 查看
 
 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.xsdhttp://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.xsd

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

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

 

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

 

 

http://www.springframework.org/schema/aop http://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
前面,否则不会正确的解析
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: