命名空间类[http://www.springframework.org/schema/batch]未实现[org.springframework.beans.factory.xml.NamespaceHandler]接口

时间:2017-12-28 18:28:24

标签: java xml spring spring-batch

我在Tomcat中启动Spring Web应用程序时收到以下错误。

基本上,在处理beans.xml文件时,将按顺序加载以下类。

org.springframework.context.config.ContextNamespaceHandler处理URI http://www.springframework.org/schema/context

org.springframework.beans.factory.xml.UtilNamespaceHandler处理URI http://www.springframework.org/schema/util

org.apache.cxf.jaxws.spring.NamespaceHandler处理URI http://cxf.apache.org/jaxws

org.apache.cxf.transport.http.spring.NamespaceHandler处理URI http://cxf.apache.org/transports/http/configuration

org.springframework.batch.core.configuration.xml.CoreNamespaceHandler处理URI http://www.springframework.org/schema/batch

但是当它为批处理URI加载上面的最后一个类时,会发生以下异常。

12/28/2017-11:21:47.070 - localhost-startStop-1 - ERROR [org.springframework.web.context.ContextLoader : Line 227]: Context initialization failed 
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [beans.xml]; nested exception is org.springframework.beans.FatalBeanException: Class [org.springframework.batch.core.configuration.xml.CoreNamespaceHandler] for namespace [http://www.springframework.org/schema/batch] does not implement the [org.springframework.beans.factory.xml.NamespaceHandler] interface
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)

我查看了上述所有类的来源,发现所有类都扩展了

org.springframework.beans.factory.xml.NamespaceHandlerSupport

反过来实现

org.springframework.beans.factory.xml.NamespaceHandler

我已经检查了类路径上的jar,它们看起来很好,在各自的预期spring jar文件中包含上面的类和接口。

知道如何解决这个问题吗?

类似的问题在这里,我已经尝试了什么。

Unexpected exception parsing XML document from class path resource [config/FaceBookSimulator.xml];

Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/batch]

更新

我使用-verbose:class选项重新启动Tomcat,以打印从任何jar文件加载的所有类。我发现了以下内容:

12/28/2017-15:01:18.251 - localhost-startStop-1 - DEBUG [org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver : Line 156]: Loaded NamespaceHandler mappings:{
 http://www.springframework.org/schema/task=org.springframework.scheduling.config.TaskNamespaceHandler, 
 http://www.springframework.org/schema/p=org.springframework.beans.factory.xml.SimplePropertyNamespaceHandler, 
 http://cxf.apache.org/transports/http-jetty/configuration=org.apache.cxf.transport.http_jetty.spring.NamespaceHandler, 
 http://www.w3.org/2006/07/ws-policy=org.apache.cxf.ws.policy.spring.PolicyNamespaceHandler, 
 http://www.springframework.org/schema/lang=org.springframework.scripting.config.LangNamespaceHandler, 
 http://www.springframework.org/schema/util=org.springframework.beans.factory.xml.UtilNamespaceHandler, 
 http://cxf.apache.org/jaxws=org.apache.cxf.jaxws.spring.NamespaceHandler, 
 http://cxf.apache.org/policy=org.apache.cxf.ws.policy.spring.NamespaceHandler, 
 http://www.springframework.org/schema/jee=org.springframework.ejb.config.JeeNamespaceHandler, 
 http://cxf.apache.org/transports/jms=org.apache.cxf.transport.jms.spring.NamespaceHandler, 
 http://cxf.apache.org/transports/http/configuration=org.apache.cxf.transport.http.spring.NamespaceHandler, 
 http://www.springframework.org/schema/tx=org.springframework.transaction.config.TxNamespaceHandler, 
 http://cxf.apache.org/bindings/object=org.apache.cxf.binding.object.spring.NamespaceHandler, 
 http://cxf.apache.org/ws/addressing=org.apache.cxf.ws.addressing.spring.NamespaceHandler, 
 http://cxf.apache.org/clustering=org.apache.cxf.clustering.spring.NamespaceHandler, 
 http://cxf.apache.org/simple=org.apache.cxf.frontend.spring.NamespaceHandler, 
 http://www.springframework.org/schema/aop=org.springframework.aop.config.AopNamespaceHandler, 
 http://www.springframework.org/schema/context=org.springframework.context.config.ContextNamespaceHandler, 
 http://cxf.apache.org/core=org.apache.cxf.bus.spring.NamespaceHandler, 
 http://cxf.apache.org/jaxrs=org.apache.cxf.jaxrs.spring.NamespaceHandler, 
 http://cxf.apache.org/binding/coloc=org.apache.cxf.binding.coloc.spring.NamespaceHandler, 
 http://schemas.xmlsoap.org/ws/2004/09/policy=org.apache.cxf.ws.policy.spring.PolicyNamespaceHandler, 
 http://www.springframework.org/schema/jms=org.springframework.jms.config.JmsNamespaceHandler, 
 http://www.springframework.org/schema/batch=org.springframework.batch.core.configuration.xml.CoreNamespaceHandler, 
 http://www.w3.org/ns/ws-policy=org.apache.cxf.ws.policy.spring.PolicyNamespaceHandler, 
 http://cxf.apache.org/ws/rm/manager=org.apache.cxf.ws.rm.spring.NamespaceHandler, 
 http://cxf.apache.org/bindings/soap=org.apache.cxf.binding.soap.spring.NamespaceHandler
} 

班级

org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver

正在处理:

http://www.springframework.org/schema/batch=org.springframework.batch.core.configuration.xml.CoreNamespaceHandler

DefaultNamespaceHandlerResolver不扩展NamespaceHandlerSupport(实现NamespaceHandler)。

如果发现是对的,如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我的应用程序依赖于服务器lib目录下的共享jar文件。有很多罐子。我需要整理服务端的jar文件。但最快的解决方案是将所需的jar包装在WAR文件的WEB-INF / lib中。