我遇到了这个奇怪的问题“无法找到 XML 模式 namespace 的 Spring NamespaceHandler”。我在 Spring 应用程序上下文中引用 GATE 命名空间。它是一个可执行的 jar,其中 java 类实例化了 spring 应用程序上下文。当我通过 eclipse 在本地机器上测试它时,它工作得很好。但是,当我尝试将它作为带有 java 主类的可执行 jar 运行时,问题就出现了。
这是一个异常(exception)。
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://gate.ac.uk/ns/spring]
Offending resource: class path resource [applicationContext.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:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:gate="http://gate.ac.uk/ns/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://gate.ac.uk/ns/spring http://gate.ac.uk/ns/spring.xsd">
架构可访问且有效。
可执行 jar 包含与门相关的 jar 文件。这是 gateway 的 pom 文件条目
<dependency>
<groupId>gate</groupId>
<artifactId>gate</artifactId>
<version>5.1</version>
</dependency>
<dependency>
<groupId>gate</groupId>
<artifactId>gate-asm</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>gate</groupId>
<artifactId>gate-compiler-jdt</artifactId>
<version>1.0</version>
</dependency>
这是java代码片段
try{
AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("/applicationContext.xml");
this.processor = (TestProcessor) ctx.getBean("testProcessor");
}catch (Exception ex) {
ex.printStackTrace();
}
这是 Gate 文档引用。
http://gate.ac.uk/releases/gate-5.0-beta1-build3048-ALL/doc/tao/splitch3.html#x5-900003.27
不确定出了什么问题,任何指示将不胜感激。
谢谢
最佳答案
gate 自定义命名空间的命名空间处理程序将在此应用程序提供的 jar 文件(gate.jar?)中指定,如果您查看该 jar 文件,您应该会看到一个 META-INF/spring.handlers 文件,其中包含以下类型的条目:
http://gate.ac.uk/ns/spring=*NamespaceHandler
这是您的程序在启动时无法找到的处理程序。您的类路径可能在主程序中关闭,或者如果您使用某些东西将 jar 组合成单个 jar(uber jar),那么跨不同 jar 文件的 META-INF/spring.handlers 文件的合并可能会变得困惑,那里如果您创建了一个 uber jar,那么有很好的解决方法。
关于java - 无法找到 Spring NamespaceHandler for XML schema 命名空间问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11440687/