spring的xml空间命名

spring的xml文件命名空间主要有三部分:xmlns和xsi:schemaLocation 以及xmlns:xsi

首先xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd“

是必须有的

xsi:schemaLocation:为指定了用于解析和校验xml的定义文件(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"
    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"> 
</beans>

xmlns:aop="http://www.springframework.org/schema/aop"一定要放置于

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的元素的定义的文件名

猜你喜欢

转载自blog.csdn.net/a990914093/article/details/84028077