无法找到 Spring NamespaceHandler util [英] Unable to locate Spring NamespaceHandler util

查看:43
本文介绍了无法找到 Spring NamespaceHandler util的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 spring v.3.1 执行我的 java 项目时,出现以下错误:

When I execute my java project with spring v.3.1 , so i get following error:

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 具有以下依赖项:

My POM has following dependency:

<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>3.1.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>3.1.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>3.1.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>3.1.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>3.1.2.RELEASE</version>
        </dependency>

还有我的 Service.xml 文件:

And my Service.xml file:

    <?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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
 http://www.springframework.org/schema/util  http://www.springframework.org/schema/util/spring-util-3.1.xsd">

    <bean id="configParser" class="com.cc.mp.srv.core.parser.ConfigParser">
        <property name="file" >
            <util:constant static-field="com.cc.mp.srv.main.Main.FILE_NAME"/>
        </property>
    </bean>

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

Why could not locate the utility schema? I insert the core dependency in the pom file. The version number are also the same. What needs Spring yet?

编辑

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}

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

If the debug messages is output, then it can be recognized that various version number is used. Could be the reason? How can the numbers be defined?

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

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

推荐答案

The Schema http://www.springframework.org/schema/util/spring-util.xsd, http://www.springframework.org/schema/util/spring-util-3.1.xsd(以及带有版本的那个)带有 spring-beans-.RELEASE.jar

The Schema http://www.springframework.org/schema/util/spring-util.xsd, http://www.springframework.org/schema/util/spring-util-3.1.xsd (and the one with the versions) come with spring-beans-<version>.RELEASE.jar

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

Add this jar to your dependencies:

<dependency>
     <groupId>org.springframework</groupId>
     <artifactId>spring-beans</artifactId>
     <version>3.1.2.RELEASE</version>
 </dependency>

<小时>

ma​​ven-assembly-plugin 的问题:

你写道:

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

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

啊...我想 maven-assembly-plugin 是导致该问题的原因.这是因为模式解析机制是这样工作的:Spring 为 XSD 文件提供了 jars.在 jar 中,META-INF 文件夹中是一个文件 schema.info.此文件包含所有 XSD 文件的列表以及此 jar 提供的位置(在 jar 中).

Ah... I guess that the maven-assembly-plugin is the cause for that problem. This is because the schema resolution mechanism works this way: Spring provides the XSD files with there jars. Within the jar, in the folder META-INF is a file schema.info. This file contains a listing of all XSD fiels and there locations (in the jar) provided by this jar.

示例: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

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

So and now you have different jars (spring-beans, spring-tx, spring-aop, spring-context...) , that all contains a META-INF/spring.schemas file, with different content. On the other hand you use maven-assembly-plugin to aggregate the content of all the jar files in a single one.

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

I guess you will have this problem with the spring.handlers file too.

看起来您可以配置 maven-assembly-plugin 来合并这些文件.请参阅:此答案i-merge-resource-files-in-a-maven-assembly">如何在Maven程序集中合并资源文件?

It looks like you can configure the maven-assembly-plugin to merge this files. see: this answer of How can I merge resource files in a Maven assembly?

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

An alternative solution would using the spring-boot-maven-plugin instead of maven-assembly-plugin

 <plugin>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-maven-plugin</artifactId>
     <version>1.2.1</version>
     <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <mainClass>YOUR.MAIN.CLASS</mainClass>
    </configuration>
 </plugin>

(或使用maven-shade-pluging)

这篇关于无法找到 Spring NamespaceHandler util的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆