cvc-complex-type.2.4.c: 匹配的通配符是严格的,但是找不到元素'aop:scoped-proxy'的声明

cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'aop:scoped-proxy'

我有一个使用 JPA 和 Oracle 作为数据库的 Spring MvC 项目,我的 servlet.xml 文件中有这个 bean 声明,但是当我 运行 一个测试

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/data/jpa
    http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/tx/spring-tx.xsd">

<bean id="bbtra" 
        class="com.bonanza.commons.services.TranslationDB"
        autowire-candidate="true">
    <property name="dataSource" ref="dataSource" />
    <aop:scoped-proxy/>
</bean>

我收到这个错误:

cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'aop:scoped-proxy'.

很可能未指定 aop 命名空间的架构位置:

<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 https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd">

    <!-- bean definitions here -->

</beans>

通常 *.xsd 文件被 https:// 而不是 http:// 引用,但这不是问题,我只是提一下。解决问题的 XML 文件的最小改动是向上 spring-tx.xsd 移动到 tx 之后。然后 XML 编辑器中的突出显示也会发生变化,即在 IntelliJ IDEA 中,您会看到 AOP 内容从灰色变为绿色。我的意思是:

<beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:jpa="http://www.springframework.org/schema/data/jpa"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:aop="http://www.springframework.org/schema/aop"
  xsi:schemaLocation="
    http://www.springframework.org/schema/data/jpa
    http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd
  "
>

  <bean id="bbtra"
    class="com.bonanza.commons.services.TranslationDB"
    autowire-candidate="true">
    <property name="dataSource" ref="dataSource" />
    <aop:scoped-proxy/>
  </bean>

</beans>

现在所有架构位置 schema/fooschema/foo/spring-foo.xsd 形成对。