用maven构建ssh时出现asm包的问题
今天把之前做的一个项目原先在服务器Tomcatg7上部署,现在部署到glassfish2.1.1上,
发现同样的war包部署到Tomcat7上就没有异常,可以正常访问,部署到glassfish2.1.1上就报异常
(1) 第一行异常很长,如下:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'businessBusinessImpl': Autowiring of fields failed;
nested exception is org.springframework.beans.factory.BeanCreationException:Could not autowire field:
private com.dao.BusinessDaoIf com.BusinessBusinessImpl.businessDao;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'businessDaoImpl' defined in class path resource [applicationContext-bean.xml]:
Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory';
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]:
Invocation of init method failed;
nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V
(2) 最后一行异常很短,如下:
Caused by: java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer
--------------
解决方法:
报 (2) 错误,随之 sessionFactory bean 也就创建失败
究其原因是 cglib-2.1.3.jar 与 cglib-nodep-2.1_3.jar 这两个包冲突,
删除 cglib-2.1.3.jar
保留 cglib-nodep-2.1_3.jar
要用 cglib-nodep-2.1_3.jar , 对应 spring 版本2.5
删除 cglib-2.1.3.jar 后,重新部署,一切正常了
很奇怪,为什么Tomcat7却没有报异常呢?
===================================================================================
如果报以下异常:
15:20:54,093 ERROR ContextLoader:203 - Context initialization failed??
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'SessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed;
nested exception is java.lang.NoSuchMethodError:
org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;
[Ljava/lang/String;Ljava/lang/String;)V
Caused by:???
java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)
-------------------------------------
解决方法:
查看lib下是否同时引用了 asm-2.2.3.jar 与 asm.jar ,如果是,请删除asm-2.2.3.jar 即可