gpt4 book ai didi

spring - 使用Spring/Jetty(或Tomcat)/Maven为REST测试配置集成测试

转载 作者:行者123 更新时间:2023-12-04 17:22:02 24 4
gpt4 key购买 nike

我想用HTTP请求测试我们的REST服务(有点黑盒测试)。但是,经过几个小时的谷歌搜索并尝试了不同的配置后,我仍然无法正确启动Jetty。这是我当前的配置(我尝试了多个不同的版本):

pom.xml

        ...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8</version>
<configuration>
<junitArtifactName>junit:junit</junitArtifactName>
<excludes>
<exclude>**/*_Roo_*</exclude>
<exclude>**/*Util*</exclude>
<exclude>**/*IT*</exclude>
</excludes>
<forkMode>once</forkMode>
<argLine>-javaagent:'${settings.localRepository}/org/springframework/spring-instrument/${org.springframework-version}/spring-instrument-${org.springframework-version}.jar' -javaagent:'${settings.localRepository}/org/aspectj/aspectjweaver/${org.aspectj-version}/aspectjweaver-${org.aspectj-version}.jar'</argLine>
<useSystemClassLoader>true</useSystemClassLoader>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.8</version>
<configuration>
<forkMode>once</forkMode>
<argLine>-javaagent:'${settings.localRepository}/org/springframework/spring-instrument/${org.springframework-version}/spring-instrument-${org.springframework-version}.jar' -javaagent:'${settings.localRepository}/org/aspectj/aspectjweaver/${org.aspectj-version}/aspectjweaver-${org.aspectj-version}.jar'</argLine>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<scanintervalseconds>10</scanintervalseconds>
<stopkey>foo</stopkey>
<stopport>9999</stopport>
<contextpath>/${project.artifactId}</contextpath>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>9090</port>
</connector>
</connectors>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanintervalseconds>0</scanintervalseconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
...

orm.xml
<!-- <context:load-time-weaver/> -->
<context:load-time-weaver weaver-class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
<context:spring-configured/>
<context:annotation-config />
<context:component-scan base-package="com.example.jump.domain">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
</context:component-scan>
<tx:annotation-driven transaction-manager="transactionManager" />

现在,我遇到了一个异常(exception):
  • java.lang.IllegalStateException:ClassLoader [org.mortbay.jetty.webapp.WebAppClassLoader]不提供'addTransformer(ClassFileTransformer)'方法。指定一个自定义的LoadTimeWeaver或使用Spring的代理启动Java虚拟机:-javaagent:org.springframework.instrument.jar

  • 我了解异常(exception)情况,但是无法解决。我还尝试了其他几种方法,例如通过MAVEN_OPTS提供javaagent或尝试将VM args设置为Jetty。问题是Google针对不同版本提供了很多“解决方案”,但没有一个在起作用。

    我目前非常沮丧,因为在Spring中很难实现像进行REST服务测试这样的常见场景。因此,如果您足够聪明地找到正确的配置,请以一种甚至猴子都可以配置的方式与我分享,我保证如果我们遇见了啤酒就在我身上。

    这是我使用的版本:
    <properties>
    <java-version>1.6</java-version>
    <org.springframework-version>3.0.5.RELEASE</org.springframework-version>
    <org.aspectj-version>1.6.9</org.aspectj-version>
    <org.slf4j-version>1.5.10</org.slf4j-version>
    <redis.version>1.0.0.BUILD-SNAPSHOT</redis.version>
    <org.jboss.hibernate.version>3.6.0.Final</org.jboss.hibernate.version>
    <net.sf.ehcache.version>2.3.1</net.sf.ehcache.version>
    </properties>

    Maven的2.21

    如果需要,我很乐意提供更多信息。就像我说的,每一个帮助都值得赞赏。

    最佳答案

    现在,jetty-maven-plugin支持运行分支的目标,您可以在其中传递JVM参数。比使用tomcat装载 cargo 或MAVEN_OPTS容易得多。

    关于spring - 使用Spring/Jetty(或Tomcat)/Maven为REST测试配置集成测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5538564/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com