由于 spring 版本不兼容,Maven-Cargo 集成测试崩溃

发布于 2024-11-04 08:49:06 字数 8157 浏览 7 评论 0原文

我正在开发一个涉及几个webapp的集成测试,但是当使用maven编译时,由于spring和spring上下文之间的版本不一致而给出了linkageError,即使我对它们使用相同的版本。 使用的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)

感谢您的回复。

I am developing an integration test involving a couple of webapps, but when compiling using maven, a linkageError is given due to version inconsistency between spring and spring context, even though I use the same version for both of them.
The pom.xml used is the following one:

....

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

...

The error produced when prompting 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)

Thanks for your replies.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

舟遥客 2024-11-11 08:49:06
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring</artifactId>
    <version>2.5.4</version>
</dependency>

这是单一的 Spring 一切发行版。如果你使用这个,你不需要任何其他 Spring Jar,它已经包含了所有内容。 (如果这样做,可能会导致类路径冲突)

这可能就是 Spring 人员决定不再在 3.0.x 中创建 spring-all jar 的原因

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

This is the monolithic Spring-everything distribution. You don't need any other Spring Jar if you use this, it already contains everything. (And classpath clashes may result if you do)

Which is probably why the Spring guys have decided to no longer create a spring-all jar in 3.0.x

小清晰的声音 2024-11-11 08:49:06

您是否也将其从 Cargo-maven2-plugin 依赖项列表中删除了?

顺便说一句,我认为您应该删除一体化的 spring 依赖项并保留 spring-context 以及您需要的内容(并且仅保留您需要的内容)。

Have you removed it from the cargo-maven2-plugin dependencies list as well?

By the way, I think you rather should delete the all-in-one spring dependency and leave spring-context, plus what you need (and only what you need).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文