I would like to test our REST service with HTTP requests (kinda blackbox testing). However, after a couple of hours googling and trying different configs, I am still not able to start Jetty correctly. Here is the my current configuration (I tried multiple different versions):
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" />
Right now, I am getting the exception:
- java.lang.IllegalStateException: ClassLoader [org.mortbay.jetty.webapp.WebAppClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar
I understand the exception, but I wasn't able to fix it. I also tried a couple of other approaches, like giving the javaagent via MAVEN_OPTS or trying to set VM args to Jetty. The problem is Google gives back a bunch of 'solutions' for different versions and none was working.
I am currently pretty frustrated that a common scenario like doing REST services tests, is so hard to achieve in Spring. So if you are clever enough to find the right configuration, please share it with me in a way that even a monkey could configure it and I promise if we ever met the beers are on me.
Here are the versions I use:
<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
I happily provide more information if needed. Like I said every help appreciated.