Java 找不到Spring NamespaceHandler util
当我使用spring v.3.1执行java项目时,出现以下错误:Java 找不到Spring NamespaceHandler util,java,spring,maven,Java,Spring,Maven,当我使用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://ww
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具有以下依赖项:
<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>
如果输出调试消息,则可以识别使用了各种版本号。这可能是原因吗?如何定义数字
我还使用maven汇编插件创建一个可执行的jar文件。模式
http://www.springframework.org/schema/util/spring-util.xsd
,http://www.springframework.org/schema/util/spring-util-3.1.xsd
(以及带有这些版本的版本)附带了Springbeans-.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添加到您的依赖项:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
现在您有了不同的JAR(Springbeans
,SpringTX
,SpringAOP
,SpringContext
…),它们都包含一个具有不同内容的META-INF/spring.schemas
文件。另一方面,您可以使用maven assembly plugin
将所有jar文件的内容聚合到一个jar文件中
我想您在spring.handlers
文件中也会遇到这个问题
看起来您可以配置maven汇编插件来合并这些文件。见:当然
另一种解决方案是使用springbootmaven插件
,而不是maven汇编插件
<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>
org.springframework.boot
springbootmaven插件
1.2.1
重新包装
你的主课
(或者使用maven shade插件
)我遇到了与maven shade插件类似的问题。我的案例中的解决方案包含在
基本上,您必须在pom.xml中向maven shade插件配置中添加一个。从下面添加2个附加变压器条目:
<configuration>
<outputDirectory>${basedir}/bin</outputDirectory>
<finalName>myName</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.foo.MyApp</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
...
</configuration>
${basedir}/bin
我的名字
com.foo.MyApp
META-INF/spring.handlers
META-INF/spring.schemas
...
你能试着从xsd导入中删除版本号吗?当我删除它们时,这是相同的错误消息。我添加了更改,但有相同的错误消息。我认为maven汇编插件是关键谢谢,是的,这是问题所在,所以我使用了maven shade插件。这是教程页面的链接,谢谢。对我来说,它在使用SpringBootMaven插件而不是maven汇编插件时工作
<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>
<configuration>
<outputDirectory>${basedir}/bin</outputDirectory>
<finalName>myName</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.foo.MyApp</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
...
</configuration>