Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jetty 9 + JDK 8 + spring 4 Annotations

After upgrading to JDK 8 , the jetty 9 is no longer able to scan the spring annotations : I get the following error :

MultiException[java.lang.RuntimeException: Error scanning file ApplicationInitializer.class, java.lang.RuntimeException: Error scanning file HibernateConfig.class, java.lang.RuntimeException: Error scanning file MailConfig.class, java.lang.RuntimeException: Error scanning file ServicesConfig.class, java.lang.RuntimeException: Error scanning file WebAppConfig.class]
at org.eclipse.jetty.annotations.AnnotationConfiguration.scanForAnnotations(AnnotationConfiguration.java:530)
at org.eclipse.jetty.annotations.AnnotationConfiguration.configure(AnnotationConfiguration.java:441)
at org.eclipse.jetty.webapp.WebAppContext.configure(WebAppContext.java:466)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1342)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:745)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)
at org.eclipse.jetty.maven.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:282)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:117)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:99)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:154)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)

It was working fine when i used jdk 7 .

The annotations it tries to scan are spring framework 4 annotations something like :

@Configuration
@EnableWebMvc
@ComponentScan("com.cityrentals.rentahouse")
@Import({ HibernateConfig.class, ServicesConfig.class, MailConfig.class })
public class WebAppConfig extends WebMvcConfigurerAdapter {

The error occurs irrespective of if the javaassist dependency is present or not

 <dependency>
   <groupId>org.javassist</groupId>
   <artifactId>javassist</artifactId>
   <version>3.18.1-GA</version>
  </dependency>

Any help is much appreciated

Thanks Suresh

like image 995
SurMan Avatar asked Apr 01 '14 13:04

SurMan


2 Answers

Because of the version differences between spring mvc Java (8) and the version of ASM bundled in Jetty, you have the kind of exceptions you have experienced.

You need to make the versions compatible with each other by downloading ASM 5.xx and replacing the following 2 files within the Jetty installation folder:

  1. asm-4.x.jar with asm-5.xx.jar

  2. asm-commons-4.x.jar with asm-commons-5.xx.jar

like image 148
GingerHead Avatar answered Sep 28 '22 22:09

GingerHead


Using jetty-9.1.x, Java 8 and Spring 4 the answer by Ginger Head is correct. Just to supplement that answer:

If you are using the jetty-runner with version 9.1.x you may notice that it uses a bundled version of asm (bundled in the jar). To get it working with the bundled version I had to add the asm-jars on the classpath, before the jetty-runner-jar and then start jetty-runner without the -jar flag and instead point out the main class (org.eclipse.jetty.runner.Runner).

So, this IS working:

java -cp lib/asm-5.x.jar:lib/asm-commons-5.x.jar:lib/asm-tree-5.x.jar:lib/jetty-runner.jar org.eclipse.jetty.runner.Runner foo.war

The following is NOT working:

java -cp -jar lib/jetty-runner.jar foo.war
or
java -cp lib/asm-5.x.jar:lib/asm-commons-5.x.jar:lib/asm-tree-5.x.jar -jar lib/jetty-runner.jar foo.war
like image 28
wassgren Avatar answered Sep 28 '22 22:09

wassgren