Java org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: 匹配的通配符是严格的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9786192/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict
提问by Soumya Simanta
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'.
I'm getting this error when I add a grid-node and ksession to my spring xml. I did some searching and looks like it a classpath issue. What dependency am I missing here ?
当我向 spring xml 添加网格节点和 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" />
My pom.xml has the following for Drools.
我的 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>
采纳答案by Xavi López
This error is being issued because the Drools XSD can't be located. In this commentin the Drools user list, it is stated that the XSD's aren't publicly available, and the xsi:schemaLocation
attribute in the XML is mapping that XSD to http://drools.org/schema/drools-spring org/drools/container/spring/drools-spring-1.2.0.xsd
, which doesn't resolve to the proper XSD.
发出此错误是因为无法找到 Drools XSD。在Drools 用户列表中的此评论中,指出 XSD 不是公开可用的,并且xsi:schemaLocation
XML 中的属性将该 XSD 映射到http://drools.org/schema/drools-spring org/drools/container/spring/drools-spring-1.2.0.xsd
,这不会解析为正确的 XSD。
Spring should be automatically handling the XSD resolution given the xmlns:drools="http://drools.org/schema/drools-spring"
attribute. One of the Drools JARs should be including a META-INF/spring.handlers
file defining the XSD mapping for the drools
namespace. Something along the lines of :
Spring 应该自动处理给定xmlns:drools="http://drools.org/schema/drools-spring"
属性的 XSD 分辨率。Drools JAR 之一应该包括META-INF/spring.handlers
定义drools
命名空间的 XSD 映射的文件。类似的东西:
http://drools.org/schema/drools-spring=some.classpath.visible.package.xsdfile.xsd
Which should be automatically handling the XSD file included in the Drools JARs.
它应该自动处理包含在 Drools JAR 中的 XSD 文件。
Try removing the last two lines of your xsi:schemaLocation
attribute in order to let Spring automatically resolve the XSD.
尝试删除xsi:schemaLocation
属性的最后两行,以便让 Spring 自动解析 XSD。
Some related links:
一些相关链接:
- Spring schemaLocation fails when there is no internet connection. Specially David Resnick's answer.
- Spring reference's Appendix D.5 Registering the handler and the schema.
- 当没有互联网连接时,Spring schemaLocation 会失败。特别是大卫·雷斯尼克的回答。
- Spring 参考的附录 D.5 注册处理程序和架构。
Of course, you could also extract that XSD from the JAR file, place it in an accessible directory from your classpath and use a classpath relative URL in xsi:schemaLocation
.
当然,您也可以从 JAR 文件中提取该 XSD,将其放在类路径中的可访问目录中,并在xsi:schemaLocation
.
By the way, it's probably a copy&paste error, but your <beans>
element is missing its closing tag.
顺便说一句,这可能是复制和粘贴错误,但您的<beans>
元素缺少其结束标记。
EDIT: It seems that Drools wasn't providing the spring.handlers
properly (at least as of December 2010, see Drools + Spring without internet ). You might need to dig through the JARs to get the XSD and reference it directly in xsi:schemaLocation
.
编辑:似乎 Drools 没有spring.handlers
正确提供(至少截至 2010 年 12 月,请参阅Drools + Spring without internet)。您可能需要深入研究 JAR 以获取 XSD 并直接在xsi:schemaLocation
.
回答by booFar
As for the error marker in Eclipse: I have only a workaround, and I doubt that there is a real solution for this.
As Xavi Lopez stated in his accepted answer, there is a spring-handlers
file in the drools-spring jar (for me, drools-spring-5.3.0.Final.jar
), under META-INF. This, however, does not reference an xsd file (although the xsd files reside in this very jar), but contains this:
至于Eclipse 中的错误标记:我只有一个解决方法,我怀疑是否有真正的解决方案。正如 Xavi Lopez 在他接受的答案中所说,spring-handlers
在流口水弹簧罐(对我来说,drools-spring-5.3.0.Final.jar
)中有一个文件,在META-INF 下。然而,这并不引用 xsd 文件(尽管 xsd 文件驻留在这个 jar 中),而是包含以下内容:
http\://drools.org/schema/drools-spring=org.drools.container.spring.namespace.SpringDroolsHandler
http\://drools.org/schema/drools-spring-1.2.0=org.drools.container.spring.namespace.SpringDroolsHandler
http\://drools.org/schema/drools-spring-1.3.0=org.drools.container.spring.namespace.SpringDroolsHandler
http\://drools.org/schema/drools-spring-1.4.0=org.drools.container.spring.namespace.SpringDroolsHandler
http\://drools.org/schema/drools-spring-1.5.0=org.drools.container.spring.namespace.SpringDroolsHandler
As you can see, it defines a handler class for each version of the xsd. This works well with spring at runtime, but I never saw it working with any version of Eclipse (nor the Spring Tool Suite).
如您所见,它为每个版本的 xsd 定义了一个处理程序类。这在运行时适用于 spring,但我从未见过它适用于任何版本的 Eclipse(也不是 Spring Tool Suite)。
I always end up turning off validationfor xsd files in the project, which - for your convenience - goes like this:
我总是最终关闭对项目中 xsd 文件的验证,为了您的方便,它是这样的:
- Select your project in Package Explorer, click File/Properties (or press Alt+Enter)
- In the Properties for projectdialog, select Validation
- Check Enable project specific settings(disable the validation only for this project)
- Uncheck Manualand Buildfor: XML Schema Validator
- Press OK
- Right-click on the project and select Validate(to revalidate the project with the modified settings)
- 在包资源管理器中选择您的项目,单击文件/属性(或按 Alt+Enter)
- 在“项目属性”对话框中,选择“验证”
- 选中启用项目特定设置(仅为此项目禁用验证)
- 取消选中Manualand Buildfor: XML Schema Validator
- 按确定
- 右键单击项目并选择验证(使用修改后的设置重新验证项目)
(I also tried to reference the xsd directly from the spring beans definition xml, but it did not work. As the handler defined in the spring-handlers
file works at runtime, this would not be a better workaround IMHO.)
(我也尝试直接从 spring bean 定义 xml 中引用 xsd,但它不起作用。由于spring-handlers
文件中定义的处理程序在运行时工作,恕我直言,这不是更好的解决方法。)