Maven shade无法找到XML架构命名空间的Spring NamespaceHandler [英] Maven shade unable to locate Spring NamespaceHandler for XML schema namespace

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

问题描述

我有一个小型的Spring项目,我已经用roo 1.2.2启动了

I've a small Spring project, that I've booted up with roo 1.2.2

我可以在Eclipse Juno中运行主类。但是,当我尝试运行使用 mvn package 构建的JAR文件时,出现以下错误:

I can run the main class just fine within Eclipse Juno. However when I try to run the JAR file built with mvn package, I get the following error:

Exception in thread "main" 
    org.springframework.beans.factory.parsing.BeanDefinitionParsingException: 
Configuration problem: Unable to locate Spring NamespaceHandler for 
    XML schema namespace [http://www.springframework.org/schema/tx]
Offending resource: class path resource [META-INF/spring/applicationContext.xml]

我正在使用Maven shade插件来构建超级JAR,具有以下配置:

I am using Maven shade plugin to build the uber JAR, with the following configuration:

<build>
    <pluginManagement>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>1.7.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>com.xyz.watcher.WatcherMain</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
            ...

在pom.xml属性中我有 < spring.version> 3.1.2.RELEASE< /spring.version> ,其中一个依赖项是:

In the pom.xml properties I have <spring.version>3.1.2.RELEASE</spring.version> and one of the dependencies is:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
    <version>${spring.version}</version>
</dependency>

应用程序上下文标题如下:

The application context header is as follows:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" 
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-3.1.xsd         
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd         
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.1.xsd         
        http://www.springframework.org/schema/jee 
        http://www.springframework.org/schema/jee/spring-jee-3.1.xsd         
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

在我的主程序中,我有:

In my main program I have:

String[] springConf = new String[] { "META-INF/spring/applicationContext.xml",
    "META-INF/spring/watcher.xml" };
BeanFactory appContext = new ClassPathXmlApplicationContext(springConf);

当我输入 mvn package 我得

[INFO] Building jar: /home/stivlo/workspace/monitor/target/monitor-0.1.0.BUILD-SNAPSHOT.jar
[INFO] --- maven-shade-plugin:1.7.1:shade (default) @ monitor ---
...
[INFO] Including org.springframework:spring-tx:jar:3.1.2.RELEASE in the shaded JAR.

任何人都可以建议我缺少什么以及如何修复我的构建以便我可以运行我的JAR?

Anyone can suggest what I am missing and how to fix my build so that I can run my JAR?

推荐答案

尝试在配置中添加 AppendingTransformer 。 maven文档中的示例特别提到这对Spring处理程序很有用。

Try adding an AppendingTransformer to your config. The example in maven documentation specifically mentions this as being useful for Spring handlers.

<project>
    ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.4.2</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <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>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>

希望这会有所帮助。

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

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