2012-08-13 81 views
2

我有一個小彈簧的項目,我已經啓動了與袋鼠1.2.2Maven的燈罩無法找到春天NamespaceHandler XML模式命名空間

我可以運行的主類的Eclipse朱諾內就好了。然而,當我嘗試運行與mvn package生成JAR文件,我得到以下錯誤:

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的樹蔭插件來構建的超級JAR,具有以下配置:

<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>和依賴關係中的一個是:

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

應用程序上下文頭如下:

<?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"> 

在我的主要節目,我有:

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?

+1

下面是一個沿着相同的行 - http://stackoverflow.com/questions/8523997/unable-to-locate-spring-namespacehandler-for-xml-schema-namespace-http-www-sp – 2012-08-13 16:53:58

回答

1

嘗試添加一個AppendingTransformer到您的配置。 maven文檔中的例子特別提到這對於Spring處理程序很有用。

<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> 

希望這會有所幫助。

相關問題