java.lang.nosuchmethoderror org.objectweb.asm.classwriter

I was working on a RESTFul Service based project. Recently I migrated the plain JDBC DAO layer to the hibernate based orm layer. As a first step I migrated one of the DAO class. When I deployed the complete solution in Tomcat, I faced the following error
java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.(Z)V
at net.sf.cglib.core.DebuggingClassWriter.(Debu ggingClassWriter.java:47)
at net.sf.cglib.core.DefaultGeneratorStrategy.getClas sWriter(DefaultGeneratorStrategy.java:30)
at net.sf.cglib.core.DefaultGeneratorStrategy.generat e(DefaultGeneratorStrategy.java:24)
at net.sf.cglib.core.AbstractClassGenerator.create(Ab stractClassGenerator.java:216)
at net.sf.cglib.core.KeyFactory$Generator.create(KeyF actory.java:145)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.jav a:117)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.jav a:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.jav a:104)
at net.sf.cglib.proxy.Enhancer.(Enhancer.java :69)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at org.springframework.aop.framework.DefaultAopProxyF actory.(DefaultAopProxyFactory.java:57)
When I looked in the project library repository realized there are 2 library of ASM, One from the Hibernate and Spring Integration module and other from the RESTFul Service implementation.

asm-3.1.jar
spring-asm-3.0.5.RELEASE.jarSo the guess was that since Spring uses CGLIG library ("cglib-2.1_3.jar" in my case) and CGLIB used ASM library in turn, there may be a conflict due to version difference.

So I replaced the CGLIB jar with the "cglib-nodep-2.1_3.jar" from the following location

http://www.findjar.com/jar/cglib/jars/cglib-nodep-2.1_3.jar.html;jsessionid=849E2D3B53A5EF3A214600DEABCCBF7B

This library contains all the dependencies and is not dependent on external dependency.

----------------------------------------------------------------------------------------------------

In case you are using maven to build then you can also try the following dependency :

<dependency>
<groupid>cglib</groupid>
<artifactid>cglib-nodep</artifactid>
<version>2.1_3</version>
</dependency>



Make the following changes where you are specifying hibernate annotation dependency (in case you have)
<dependency>
<groupid>org.hibernate</groupid>
<artifactid>hibernate-annotations</artifactid>
<version>${hibernate.version}</version>
<exclusions>
<exclusion>
<groupid>cglib</groupid>
<artifactid>cglib</artifactid>
</exclusion>
</exclusions>
</dependency>
And following changes where you are specifying hibernate core dependency:

<dependency>
<groupid>org.hibernate</groupid>
<artifactid>hibernate-core</artifactid>
<version>${hibernate.version}</version>
<exclusions>
<exclusion>
<groupid>asm</groupid>
<artifactid>asm</artifactid>
</exclusion>
<exclusion>
<groupid>asm</groupid>
<artifactid>asm-attrs</artifactid>
</exclusion>
<exclusion>
<groupid>cglib</groupid>
<artifactid>cglib</artifactid>
</exclusion>
</exclusions>
</dependency>







Comments

  1. I have exactly the same problem. Thanks for the great solution!!!

    ReplyDelete
  2. I am glad that I could be of any help

    ReplyDelete
  3. Awesome contribution my man!... I hope you're still around keeping up your work. Best regards!

    ReplyDelete
  4. It worked for me too... Thanks

    ReplyDelete
  5. It worked for me...Thanks a lot..

    ReplyDelete
  6. Really great work,It helped me to solve my issue.

    ReplyDelete

Post a Comment

Popular posts from this blog

Hibernate: a different object with the same identifier value was already associated with the session

BeanDefinitionStoreException: Failed to parse configuration class: Could not find class [javax.jms.ConnectionFactory]