My build system is maven based. The things I love about maven (for regular developer tasks)is its dependency resolution capablities as well as the eclipse:eclipse plugin which helps me setup eclipse in no time.
When I added a dependency on spring-aop and spring-aspects my application stopped deplying complainig about a class in asm that was not found. The exception was comming from hibernate trying to proxy an object using cglib. This was the stacktrace I was getting:
java.lang.NoClassDefFoundError: org/objectweb/asm/CodeVisitor
at net.sf.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:165)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
at net.sf.cglib.proxy.Enhancer.
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:107)
at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.
at org.hibernate.tuple.entity.PojoEntityTuplizer.
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.
at org.hibernate.tuple.entity.EntityMetamodel.
at org.hibernate.persister.entity.AbstractEntityPersister.
at org.hibernate.persister.entity.SingleTableEntityPersister.
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:805)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:745)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1175)
and more stuff which adds no value to this blog entry.
The problem, after hours of digging, banging, pulling hair and snapping was the hibernate's pom.xml has cglig-2.1_3.jar as dependency and somehow this guy depends on asm-1.5.x.jar. Spring aop depends indirectly of asm-2.2.3 and maven, smart enough, was using the latter is its a newer version. To make a long story short, I added an exclussion to hibernate dependency for cglib and added cglib-nodep as one of my dependencies and this solved the problem.
I hope, if anyone hits this problem ever, he/she will google the stacktrace and will find this post.
2 comments:
Please, could you show your pom file?
I've got same problem
Yes, thanks
Post a Comment