2011-05-03 87 views
0

我正在開發一個涉及幾個webapps的集成測試,但是當使用maven編譯時,由於spring和spring上下文之間的版本不一致,給出了linkageError,儘管我使用兩者都是相同的版本。 使用的pom.xml的是以下各項之一:Maven-Cargo集成測試因彈簧版本不兼容而崩潰

....

<dependencies> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring</artifactId> 
     <version>2.5.4</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>2.5.4</version> 
    </dependency> 

    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.8.2</version> 
    </dependency> 

</dependencies> 

...

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 
      </configuration> 
     </plugin> 

     <!-- Copies the war from repository and deploys on a jetty server --> 
     <plugin> 
      <groupId>org.codehaus.cargo</groupId> 
      <artifactId>cargo-maven2-plugin</artifactId> 
      <version>1.1.0-SNAPSHOT</version> 
      <configuration> 
       <!-- Container configuration --> 
       <container> 
        <containerId>jetty6x</containerId> 
        <type>embedded</type> 
        <dependencies> 
         <dependency> 
          <groupId>org.springframework</groupId> 
          <artifactId>spring</artifactId> 
         </dependency> 
         <dependency> 
          <groupId>org.springframework</groupId> 
          <artifactId>spring-context</artifactId> 
         </dependency> 
        </dependencies> 
       </container> 
       <!-- Configuration with the required deployable wars --> 
       <configuration> 
        <deployables> 
         <deployable> 
          <groupId>group</groupId> 
          <artifactId>artifact</artifactId> 
          <type>war</type> 
          <properties> 
           <context>war context</context> 
          </properties> 
         </deployable> 
        </deployables> 
       </configuration> 
    <!-- Don't wait, execute the tests after the container is started --> 
       <wait>false</wait> 
      </configuration> 
      <executions> 
       <execution> 
        <id>start-container</id> 
        <phase>generate-sources</phase> 
        <goals> 
         <goal>start</goal> 
        </goals> 
       </execution> 
       <execution> 
        <id>stop-container</id> 
        <phase>post-verify</phase> 
        <goals> 
         <goal>stop</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

...

提示MVN驗證時錯誤產生:

2011-05-03 09:19:54.919:WARN::failed [email protected]: java.lang.LinkageError: loader constraint violation: when resolving overridden method "org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.getResourceByPath(Ljava/lang/String;)Lorg/springframework/core/io/Resource;" the class loader (instance of org/mortbay/jetty/webapp/WebAppClassLoader) of the current class, org/springframework/web/context/support/AbstractRefreshableWebApplicationContext, and its superclass loader (instance of java/net/URLClassLoader), have different Class objects for the type org/springframework/core/io/Resource used in the signature 
2011-05-03 09:19:54.919:WARN::failed [email protected]: java.lang.LinkageError: loader constraint violation: when resolving overridden method "org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.getResourceByPath(Ljava/lang/String;)Lorg/springframework/core/io/Resource;" the class loader (instance of org/mortbay/jetty/webapp/WebAppClassLoader) of the current class, org/springframework/web/context/support/AbstractRefreshableWebApplicationContext, and its superclass loader (instance of java/net/URLClassLoader), have different Class objects for the type org/springframework/core/io/Resource used in the signature 
2011-05-03 09:19:54.919:WARN::Error starting handlers 
java.lang.LinkageError: loader constraint violation: when resolving overridden method "org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.getResourceByPath(Ljava/lang/String;)Lorg/springframework/core/io/Resource;" the class loader (instance of org/mortbay/jetty/webapp/WebAppClassLoader) of the current class, org/springframework/web/context/support/AbstractRefreshableWebApplicationContext, and its superclass loader (instance of java/net/URLClassLoader), have different Class objects for the type org/springframework/core/io/Resource used in the signature 
    at java.lang.Class.getDeclaredConstructors0(Native Method) 
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389) 
    at java.lang.Class.getConstructor0(Class.java:2699) 
    at java.lang.Class.getDeclaredConstructor(Class.java:1985) 
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:61) 
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:249) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45) 
    at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:549) 
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:136) 
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1282) 
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:518) 
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:499) 
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) 
    at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152) 
    at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156) 
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) 
    at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152) 
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) 
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130) 
    at org.mortbay.jetty.Server.doStart(Server.java:224) 
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.codehaus.cargo.container.jetty.internal.JettyExecutorThread.run(JettyExecutorThread.java:69) 

感謝您的回覆。

回答

1
<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring</artifactId> 
    <version>2.5.4</version> 
</dependency> 

這是單片式的Spring-everything分佈。如果你使用它,你不需要任何其他的Spring Jar,它已經包含了一切。 (並可能導致衝突的classpath如果你這樣做)

這可能是爲什麼春天傢伙已經決定不再創造3.0.x的彈簧所有jar

+0

我已經刪除了你所說的spring-context依賴關係,並且仍然出現同樣的錯誤。有沒有辦法獲得哪個春季版本使用貨物插件? – Josep 2011-05-03 09:02:36

1

你從貨物maven2-刪除它插件依賴列表以及?順便說一句,我認爲你應該刪除所有功能於一身的spring依賴項,並留下spring-context,加上你所需要的(只有你需要的)。