<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="https://www.springframework.org/schema/beans"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xmlns:context="https://www.springframework.org/schema/context"
xmlns:aop="https://www.springframework.org/schema/aop"
xmlns:tx="https://www.springframework.org/schema/tx"
xmlns:mvc="https://www.springframework.org/schema/mvc"
xsi:schemaLocation="
https://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
https://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
https://www.springframework.org/schema/aop
https://www.springframework.org/schema/aop/spring-aop.xsd
https://www.springframework.org/schema/tx
https://www.springframework.org/schema/tx/spring-tx.xsd
https://www.springframework.org/schema/mvc
https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- 配置內容 -->
</beans>
| 屬性 | 作用 | 說明 |
|---|---|---|
| xmlns (默認) | 默認命名空間 | beans 標籤及無前綴標籤歸屬 |
| xmlns:xsi | XML Schema 實例 | 啟用 schemaLocation 驗證 |
| xmlns:context | 組件掃描命名空間 | <context:component-scan/> 等 |
| xmlns:aop | AOP 命名空間 | <aop:config/>, <aop:aspect/> 等 |
| xmlns:tx | 事務命名空間 | <tx:annotation-driven/> 等 |
| xsi:schemaLocation | Schema 文件位置映射 | 命名空間 URI → XSD 文件 URL/路徑 |
spring-beans.xsd 自動匹配當前 Spring 版本(推薦)spring-beans-5.3.xsd 鎖定版本,升級需手動修改META-INF/spring.schemas 映射本地 XSD,離線也能驗證<!-- 數據訪問 -->
xmlns:jdbc="https://www.springframework.org/schema/jdbc"
xmlns:jpa="https://www.springframework.org/schema/data/jpa"
<!-- 任務調度 -->
xmlns:task="https://www.springframework.org/schema/task"
<!-- 消息隊列 -->
xmlns:jms="https://www.springframework.org/schema/jms"
<!-- 安全框架 -->
xmlns:security="https://www.springframework.org/schema/security"
IntelliJ IDEA:Settings → Schemas and DTDs → 添加 Spring XSD 映射
Eclipse:Preferences → XML → XML Catalog → Add User Entry