Сбой теста интеграции Maven-Cargo из-за несовместимости весенней версии - PullRequest
0 голосов
/ 03 мая 2011

Я разрабатываю интеграционный тест, включающий несколько веб-приложений, но при компиляции с использованием maven выдается linkageError из-за несоответствия версий между контентом Spring и Spring, хотя я использую одну и ту же версию для них обоих. Используется pom.xml:

....

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

2011-05-03 09:19:54.919:WARN::failed ContextHandlerCollection@10cafa1: 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 HandlerCollection@1de7497: 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)

Спасибо за ваши ответы.

Ответы [ 2 ]

1 голос
/ 03 мая 2011

Вы также удалили его из списка зависимостей cargo-maven2-plugin?

Кстати, я думаю, вам лучше удалить все-в-одном пружинную зависимость и оставить контекст пружины, плюс то, что вам нужно (и только то, что вам нужно).

1 голос
/ 03 мая 2011
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring</artifactId>
    <version>2.5.4</version>
</dependency>

Это монолитный дистрибутив Spring-everything.Вам не нужен другой Spring Jar, если вы используете его, он уже содержит все.(И если вы это сделаете, могут произойти столкновения с использованием путей к классам)

Вероятно, поэтому ребята из Spring решили больше не создавать банку с пружинами в версии 3.0.x

...