java-org.xml.sax.SAXParseException:cvc-complex-type.2.4.c:匹配的通配符是严格的

提问

org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'drools:grid-node'. 

当我在spring xml中添加grid-node和ksession时,出现此错误.我做了一些搜索,看起来像是类路径问题.我在这里缺少什么依赖性?

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
    xmlns:drools="http://drools.org/schema/drools-spring"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://camel.apache.org/schema/spring
       http://camel.apache.org/schema/spring/camel-spring.xsd
       http://www.springframework.org/schema/context 
       http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
       http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas
       http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
       http://drools.org/schema/drools-spring org/drools/container/spring
       http://drools.org/schema/drools-spring org/drools/container/spring/drools-spring-1.2.0.xsd">


    <drools:grid-node id="node1"/>
    <drools:ksession id="ksession1" type="stateful" kbase="kbase1" node="node1" />

我的pom.xml具有Drools的以下内容.

               <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-camel</artifactId>
        <version>${drools.version}</version>
        <exclusions>
            <!-- This ensures that we use the latest version of Spring jars and not 
                the one that comes with drools.version. -->
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring</artifactId>
            </exclusion>

            <exclusion>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-core</artifactId>
            </exclusion>

            <exclusion>
              <groupId>org.apache.camel</groupId>
              <artifactId>camel-spring</artifactId>
            </exclusion>



            <exclusion>
                <artifactId>camel-xstream</artifactId>
                <groupId>org.apache.camel</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>knowledge-api</artifactId>
        <version>${drools.version}</version>
    </dependency>

    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-core</artifactId>
        <version>${drools.version}</version>
    </dependency>


    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-compiler</artifactId>
        <version>${drools.version}</version>
    </dependency>


    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-spring</artifactId>
        <version>${drools.version}</version>
    </dependency>

最佳答案

由于找不到Drools XSD而发出此错误.在Drools用户列表中的this comment中,声明XSD不公开可用,并且XML中的xsi:schemaLocation属性将XSD映射到http://drools.org/schema/drools-spring org / drools /container/spring/drools-spring-1.2.0.xsd,无法解析为正确的XSD.

给定xmlns:drools =“ http://drools.org/schema/drools-spring”属性,Spring应该自动处理XSD分辨率. Drools JAR之一应该包括META-INF / spring.handlers文件,该文件定义了Drools名称空间的XSD映射.类似于以下内容:

http://drools.org/schema/drools-spring=some.classpath.visible.package.xsdfile.xsd

应该自动处理Drools JAR中包含的XSD文件.

尝试删除xsi:schemaLocation属性的最后两行,以便让Spring自动解析XSD.

一些相关链接:

>Spring schemaLocation fails when there is no internet connection.特别是David Resnick的回答.
>春季参考文献的Appendix D.5 Registering the handler and the schema.

当然,您也可以从JAR文件中提取该XSD,将其放在类路径的可访问目录中,并在xsi:schemaLocation中使用类路径相对URL.

顺便说一句,这可能是复制和粘贴错误,但是您的< beans>元素缺少其结束标记.

编辑:看来Drools没有正确提供spring.handlers(至少从2010年12月开始,请参阅Drools + Spring without internet ).您可能需要深入研究JAR以获得XSD并直接在xsi:schemaLocation中引用它.