spring 引入命名空间简介
来源:互联网 发布:java工程师待遇怎么样 编辑:程序博客网 时间:2024/06/05 13:25
spring 引入命名空间
spring 整合了各种工具,并且spring提供了对各种工具的xml scheme 的配置方式,简化了开发。
对于各种命名空间的引入的方法,现做以下说明
<?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>
<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
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
是必须有的
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
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: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
http://www.springframework.org/schema/aop(空格)http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
而/spring-aop-2.5.xsd就是aop的元素的定义的文件名
最后配好后类似于
<?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>
<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>
<?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:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
4 0
- spring 引入命名空间简介
- spring 引入命名空间
- Spring命名空间如何引入
- spring 命名空间引入方法
- Spring配置文件之引入命名空间
- JavaScript 编程引入命名空间
- js模拟引入命名空间
- php命名空间与引入
- net 命名空间简介
- PHP命名空间简介
- Spring命名空间
- Spring 命名空间 p
- Spring配置文件命名空间
- Spring常用命名空间
- spring中的命名空间
- spring命名空间
- Spring 命名空间配置
- Spring常用命名空间
- php单例模式
- LeetCode Single Number II
- 【BZOJ4544】椭圆上的整点 数学
- Spark-再接着上次的Lamda架构
- linux中的svn命令使用
- spring 引入命名空间简介
- 汉诺塔V
- u-boot配置和编译过程详解
- Windows下Eclipse+PyDev安装Python开发环境
- 使用VS2012 的快捷键
- 详解JVM中的Minor GC、FullGC
- spring 数据连接泄漏
- POJ 3304 Segments(判断直线和线段相交)
- 关机/重启命令