今天发布公司的网站出现一个棘手的问题,通过Google查询一个钟头才解决,所以决定记录解决办法以防下次出现同样的问题。
首先网站在本地windows下面没有任何错误,但是发布到linux 下面就会报错,第一个问题如下:
net.sf.cglib.core.CodeGenerationException: Java.lang.reflect.InvocationTargetException–>null
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at net.sf.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:126)
at org.hibernate.proxy.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:41)
at org.hibernate.tuple.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:161)
at org.hibernate.tuple.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:131)
at org.hibernate.tuple.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.TuplizerLookup.create(TuplizerLookup.java:64)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:257)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:412)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:108)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory
然后经过查找相关资料, 解决方案1: 删除WEB-INF/lib/asm-2.2.3.jar 然后重启 Tomcat,无效… 解决方案2: 下载asm-all-3.0.jar替换掉所有asm开头的jar包.无效… 解决方案3: 如果在lib目录下有2.13的版本,请更换为cglib-2.2_1.jar即可。重新发布项目.无效…. 项目中使用了ehcache做为hibernate的缓存,ehcache-1.1.jar也导入了.
接着出现如下错误,java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:47)
at net.sf.cglib.core.DefaultGeneratorStrategy.getClassWriter(DefaultGeneratorStrategy.java:30)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:144)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:116)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
通过各种查询,实验各种方法,最后把成功的解决办法记录一下。因为cglib 包和asm包冲突开始用的cglib包是cglib-2.1.3.jar ,后来换了一个cglib-nodep-2.2.jar运行成功。