當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring命名空间引入方法
生活随笔
收集整理的這篇文章主要介紹了
Spring命名空间引入方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
spring 整合了各種工具,并且spring提供了對各種工具的xml scheme 的配置方式,簡化了開發。 但是對于各種工具的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"
????xmlns:aop="http://www.springframework.org/schema/aop"
????xmlns:context="http://www.springframework.org/schema/context"
????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.5.xsd
????????http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
????????http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
????????http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
</beans> ? 首先xmlns="http://www.springframework.org/schema/beans"
????xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance 是必須存在的,可以從spring的文檔和例子中查找到, xsi:schemaLocation 指定了用于解析和校驗xml的定義文件(xsd)的位置。 我們以添加aop命名空間為例: 在spring.jar文件中的META—INF目錄中提供了spring.schemas 文件,這個文件指定了提供支持的功能的 xml元素配置的命名空間定義文件的位置,在這個文件中我們可以找到aop的位置: 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 那么我們可以在spring.jar文件的對應目錄中找到這些xsd文件,打開文件以后, 可以看到標簽:<xsd:schema xmlns="http://www.springframework.org/schema/aop"
??xmlns:xsd="http://www.w3.org/2001/XMLSchema"
??xmlns:beans="http://www.springframework.org/schema/beans"
??xmlns:tool="http://www.springframework.org/schema/tool"
??targetNamespace="http://www.springframework.org/schema/aop"
??elementFormDefault="qualified"
??attributeFormDefault="unqualified"> 那么第一個xmlns就是要引進的命名空間,但是在引進applicationContext.xml之前需要修改為: xmlns:aop="http://www.springframework.org/schema/aop",之后添加入applicationContext.xml文件中,且一定要放置于xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"之后,順序不能錯。 之后需要在xsi:schemaLocation 中添加位置:
http://www.springframework.org/schema/aop(空格)http://www.springframework.org/schema/aop/spring-aop-2.5.xsd 而/spring-aop-2.5.xsd就是aop的元素的定義的文件名
<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:context="http://www.springframework.org/schema/context"
????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.5.xsd
????????http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
????????http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
????????http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
</beans> ? 首先xmlns="http://www.springframework.org/schema/beans"
????xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance 是必須存在的,可以從spring的文檔和例子中查找到, xsi:schemaLocation 指定了用于解析和校驗xml的定義文件(xsd)的位置。 我們以添加aop命名空間為例: 在spring.jar文件中的META—INF目錄中提供了spring.schemas 文件,這個文件指定了提供支持的功能的 xml元素配置的命名空間定義文件的位置,在這個文件中我們可以找到aop的位置: 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 那么我們可以在spring.jar文件的對應目錄中找到這些xsd文件,打開文件以后, 可以看到標簽:<xsd:schema xmlns="http://www.springframework.org/schema/aop"
??xmlns:xsd="http://www.w3.org/2001/XMLSchema"
??xmlns:beans="http://www.springframework.org/schema/beans"
??xmlns:tool="http://www.springframework.org/schema/tool"
??targetNamespace="http://www.springframework.org/schema/aop"
??elementFormDefault="qualified"
??attributeFormDefault="unqualified"> 那么第一個xmlns就是要引進的命名空間,但是在引進applicationContext.xml之前需要修改為: xmlns:aop="http://www.springframework.org/schema/aop",之后添加入applicationContext.xml文件中,且一定要放置于xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"之后,順序不能錯。 之后需要在xsi:schemaLocation 中添加位置:
http://www.springframework.org/schema/aop(空格)http://www.springframework.org/schema/aop/spring-aop-2.5.xsd 而/spring-aop-2.5.xsd就是aop的元素的定義的文件名
轉載于:https://www.cnblogs.com/Neil223/p/5759780.html
總結
以上是生活随笔為你收集整理的Spring命名空间引入方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: iOS中正则表达式的使用
- 下一篇: 网络编程之TCP