java – 无法找到Spring NamespaceHandler util

前端之家收集整理的这篇文章主要介绍了java – 无法找到Spring NamespaceHandler util前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

当我用spring v.3.1执行我的java项目时,我得到以下错误

Bean 'configParser'; nested exception is 

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/util]
Offending resource: class path resource [Services.xml]
Bean 'configParser'

我的POM具有以下依赖性:

我的Service.xml文件:

    

为什么找不到实用程序架构?我在pom文件中插入核心依赖项.版本号也是一样的.
什么需要春天呢?

编辑

Loading schema mappings from [META-INF/spring.schemas]
2015-01-31 18:56:11,553 DEBUG (main) [org.springframework.beans.factory.xml.PluggableSchemaResolver] - Loaded schema mappings: {http://www.springframework.org/schema/tx/spring-tx-2.5.xsd=org/springframework/transaction/config/spring-tx-2.5.xsd,http://www.springframework.org/schema/tx/spring-tx-3.1.xsd=org/springframework/transaction/config/spring-tx-3.1.xsd,http://www.springframework.org/schema/tx/spring-tx-2.0.xsd=org/springframework/transaction/config/spring-tx-2.0.xsd,http://www.springframework.org/schema/tx/spring-tx.xsd=org/springframework/transaction/config/spring-tx-3.1.xsd,http://www.springframework.org/schema/tx/spring-tx-3.0.xsd=org/springframework/transaction/config/spring-tx-3.0.xsd}

如果输出调试消息,则可以识别出使用了各种版本号.可能是原因?如何定义数字?

我还使用maven-assembly-plugin来创建一个可执行的jar文件.

最佳答案
Schema http://www.springframework.org/schema/util/spring-util.xsd,http://www.springframework.org/schema/util/spring-util-3.1.xsd(以及版本的版本) )来自spring-beans-< version> .RELEASE.jar

将此jar添加到您的依赖项:

maven-assembly-plugin的问题:

你写了:

I also use the maven-assembly-plugin to create a executable jar file.

啊……我猜maven-assembly-plugin是造成这个问题的原因.这是因为模式解析机制以这种方式工作:Spring提供带有jar的XSD文件.在jar中,文件夹META-INF是一个文件schema.info.此文件包含所有XSD fiels的列表以及此jar提供的位置(在jar中).

例如:spring.sug of spring-beans-3.1.1.RELEASE.jar

http\://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans-2.0.xsd
http\://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.1.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd
http\://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd
http\://www.springframework.org/schema/tool/spring-tool-2.0.xsd=org/springframework/beans/factory/xml/spring-tool-2.0.xsd
http\://www.springframework.org/schema/tool/spring-tool-2.5.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd
http\://www.springframework.org/schema/tool/spring-tool-3.0.xsd=org/springframework/beans/factory/xml/spring-tool-3.0.xsd
http\://www.springframework.org/schema/tool/spring-tool-3.1.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd
http\://www.springframework.org/schema/tool/spring-tool.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd
http\://www.springframework.org/schema/util/spring-util-2.0.xsd=org/springframework/beans/factory/xml/spring-util-2.0.xsd
http\://www.springframework.org/schema/util/spring-util-2.5.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd
http\://www.springframework.org/schema/util/spring-util-3.0.xsd=org/springframework/beans/factory/xml/spring-util-3.0.xsd
http\://www.springframework.org/schema/util/spring-util-3.1.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd
http\://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd

所以现在你有不同的jar(spring-bean,spring-tx,spring-aop,spring-context …),它们都包含一个META-INF / spring.schemas文件,内容不同.另一方面,您使用maven-assembly-plugin在一个jar文件中聚合所有jar文件的内容.

我猜你也会遇到spring.handlers文件的这个问题.

看起来您可以配置maven-assembly-plugin来合并这些文件.见:this answerthis answer

另一种解决方案是使用spring-boot-maven-plugin而不是maven-assembly-plugin

 

(或使用maven-shade-pluging)

猜你在找的Spring相关文章