Spring XML 配置文件開頭很長:
<?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:p="https://www.springframework.org/schema/p"
xsi:schemaLocation="https://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
| 片段 | 作用 |
|---|---|
| `xmlns="https://www.springframework.org/schema/beans"` | 默認命名空間,無前綴標籤屬於 beans schema |
| `xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"` | 引入 XML Schema 實例命名空間,用於 `xsi:schemaLocation` |
| `xmlns:p="https://www.springframework.org/schema/p"` | 引入 p-namespace,支援 ` |
| `xsi:schemaLocation="... spring-beans-3.0.xsd"` | 將默認命名空間映射到具體 XSD 文件位置,IDE 用於驗證、補全 |
| `spring-beans-3.0.xsd` | Schema 版本,**建議不帶版本號**(如 `spring-beans.xsd`),由 Spring 運行時根據版本自動解析最新兼容 XSD |
xsi:schemaLocation="https://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd"
<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">
Spring XML 頭部**不固定**(隨版本、所需命名空間變化),**無需手寫**,**IDE 一鍵生成**。初學階段**手寫一次**以理解命名空間、Schema 驗證、版本映射機制;實際開發**完全依賴 IDE 模板/補全**。現代項目更推薦 **Java Config (`@Configuration` + `@Bean`)** 或 **Spring Boot 自動配置**,極大減少 XML 使用。
ClassNotFoundException: weka.classifiers.Classifier:缺少依賴 JAR 排查
Linux 下 GCC 編譯成功但運行提示找不到共享庫的解決
Hadoop MapReduce 處理 VectorWritable 類型:自定義 InputFormat 與 Writable 實現指南
Java super 關鍵字全解析:return super.method() 的調用鏈與返回值傳遞