1.下载spring的xsd文件
约束文件
spring源码、约束文件和文档说明下载地址:http://repo.spring.io/release/org/springframework/spring/
例如:点击spring-framework-5.0.4.RELEASE-schema.zip ,下载schema约束文件
spring xml配置文件头命名空间 xsd文件配置
Schema文件 | 说明 |
---|---|
spring-beans-4.0.xsd | [说明]:Spring4.0最主要的Schema,用于配置Bean |
spring-aop-4.0.xsd | [说明]:AOP的配置定义的Schema |
spring-tx-4.0.xsd | [说明]:声明式事务配置定义的Schema |
spring-mvc-4.0.xsd | [说明]:MVC配置的Schema,是Spring3.0新增的 |
spring-util-4.0.xsd | [说明]:为简化某些复杂的标准配置提供的Schema |
spring-jdbc-4.0.xsd | [说明]:为配置Spring内嵌数据库提供的Schema,是Spring3.0新增的 |
示例: |
<?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.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
</beans>
xmlns=“http://www.springframework.org/schema/beans” ;
默认命名空间
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi标准命名空间,用于指定自定义命名空间的Schema文件
xmlns:aop=“http://www.springframework.org/schema/aop”
自定义命名空间
aop是该命名空间的简称
http://www.springframework.org/schema/aop 命名空间的全称,必须在xsi命名空间为其指定空间对应的Schema文件
xsi:schemaLocation=“…”
为每个命名空间指定具体的Schema文件
语法为:
<命名空间1>——<命名空间1Schema文件>——<命名空间2>——<命名空间2Schema文件>
——代表空格或回车分隔符
命名空间一般写全称,Schema文件就是 .xsd文件
2.在IDEA中配置spring的xsd文件
URL值:
#beans的key值
http://www.springframework.org/schema/beans/spring-beans.xsd
#util的key值
http://www.springframework.org/schema/util/spring-util.xsd
#jee的key值
http://www.springframework.org/schema/jee/spring-jee.xsd
#lang的key值
http://www.springframework.org/schema/lang/spring-lang.xsd
#jms的key值
http://www.springframework.org/schema/jms/spring-jms.xsd
#aop的key值
http://www.springframework.org/schema/aop/spring-aop.xsd
#tx的key值
http://www.springframework.org/schema/tx/spring-tx.xsd
#context的key值
http://www.springframework.org/schema/context/spring-context.xsd
#jdbc的key值
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
#cache的key值
http://www.springframework.org/schema/cache/spring-cache.xsd
#mvc的key值
http://www.springframework.org/schema/mvc/spring-mvc.xsd
#oxm的key值
http://www.springframework.org/schema/oxm/spring-oxm.xsd
#task的key值
http://www.springframework.org/schema/task/spring-task.xsd
#tool的key值
http://www.springframework.org/schema/tool/spring-tool.xsd
#websocket的key值
http://www.springframework.org/schema/websocket/spring-websocket.xsd
导入下好的xsd文件即可