cvc-complex-type.2.4.c:匹配的通配符是严格的,但找不到元素'context:component-scan'

问题描述

我在我们的一些遗留代码库中收到此错误

德国:org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 74; cvc-complex-type.2.4.c: Übereinstimmungsplatzhalter ist streng,aber es kann keine Deklaration für Element 'context:component-scan' gefunden werden.

EN(我在网上找到了这个翻译):The matching wildcard is strict,but no declaration can be found for element 'context:component-scan'

导致 XML

注意:为了清楚起见,我添加评论

<?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:batch="http://www.springframework.org/schema/batch"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:oxm="http://www.springframework.org/schema/oxm"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
        http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd">

<!-- This is line 14 --><context:component-scan base-package="de.continentale.mss.sinfonima" />
    <bean 
        class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
        <property name="locations">
            <array>
                <bean class="org.springframework.core.io.FileSystemResource">
                    <constructor-arg>
                        <value>./sinfonima-config/sinfonima-ve.db.prod.properties</value>
                    </constructor-arg>
                </bean>
                <bean class="org.springframework.core.io.ClassPathResource">
                    <constructor-arg>
                        <value>sinfonima-ve.datasource-test.properties</value>
                    </constructor-arg>
                </bean>
            </array>
        </property>
        <property name="ignoreResourceNotFound" value="true" />
    </bean>
    <import resource="classpath:/meta-inf/sinfonima/sinfonima-commandline.xml" />
    <import resource="classpath:/meta-inf/sinfonima/sinfonima-datasources.xml" />
    <import resource="classpath:/meta-inf/sinfonima/sinfonima-batch.xml" />
</beans>

我的尝试

使用 Eclipse 的验证机制验证 XML 时,验证完成 with no errors or warnings

在研究这个错误时,我发现了这个 SO-Question,但没有一个答案解决了我的错误The matching wildcard is strict,but no declaration can be found for element 'context:component-scan

在谷歌搜索错误时,我发现了很多山寨资源,这些资源清楚地抓取了一个或另一个 SO 问题,但不幸的是,这些资源都没有帮助我。

环境

C:\eclipse\jdk8\bin>java.exe -version
openjdk version "1.8.0_265"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_265-b01)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.265-b01,mixed mode)
C:\eclipse>type .eclipseproduct
name=Eclipse Platform
id=org.eclipse.platform
version=4.15.0

解决方法

问题是意外更新的依赖项。感谢 Marten 为我指明了这个方向。一个公司特定的 maven 目标在没有确认的情况下更新了我的依赖项,并在这样做时跳转了一个主要版本。

将这些依赖项返回到以前的版本时,错误不再发生。