org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: The matching wildcard is strict, but no declaration can be found for element 'aop:config'.
Spring XML 配置文件頭部的 xsi:schemaLocation 屬性要求:**命名空間 URI 在前,XSD 文件路徑在後**,且成對出現。順序錯誤導致 Spring 無法正確解析命名空間對應的 Schema,進而報「找不到元素聲明」。
<beans ...
xsi:schemaLocation="
https://www.springframework.org/schema/aop/spring-aop.xsd
https://www.springframework.org/schema/aop
... ">
此處將 XSD 路徑寫在了 URI 前面。
<beans xmlns="https://www.springframework.org/schema/beans"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="https://www.springframework.org/schema/aop"
xsi:schemaLocation="
https://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.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/context https://www.springframework.org/schema/context/spring-context.xsd">
<aop:config>...</aop:config>
</beans>
<?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"
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">
<!-- Bean 定義 -->
</beans>
URI XSD 換行書寫,便於排查。xmlns:aop)必須與使用的標籤前綴(aop:config)一致。spring-aop.xsd),Spring 會根據當前 Jar 版本自動解析;寫死版本(如 spring-aop-4.3.xsd)升級時易報錯。Alt+Enter 可快速修復命名空間導入。