最近在学习搭建SSH框架的时,当我发布站点时总是会出现这样的异常:
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resource' defined in ServletContext resource [/WEB-INF/spring-service.xml]: Cannot resolve reference to bean 'resourceData' while setting bean property 'resourceData'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceData' defined in ServletContext resource [/WEB-INF/spring-service.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [test.impls.ResourceDAOImpl]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError:
org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1244)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1008)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
.....................
打开WebRoot\WEB-INF\lib 文件夹下面发现有两个一样的asm包,(asm.jar 和asm-2.2.3.jar), 一个来自Hibernate 3.2 Core Libraries(asm.jar) , 一个来自Spring 2.5 AOP Libraries(asm-2.2.3.jar). 当我打asm-2.2.3.jar 直接删除时站点可以运行成功。原来是asm包有冲突。 问题还没有解决,当我们下次再重新发布时asm-2.2.3.jar文件还是会自动生成的,所以我们要去myeclipes 中把 spring 2.5 aop Libraries 中jar 文件删除。打开目录(我的MyEclipes 装在D盘):D:/Program Files/MyEclipse 6.5/myeclipse/eclipse/plugins/com.genuitec.eclipse.springframework_6.5.0.zmyeclipse650200806/data/2.0/lib/asm/ 将“asm-2.2.3.jar”文件删除即可。 同理,当你在运到用log4j.jar 时也会发现会存在两个log4j包也有两个,你可以用同样的办法去删除其中之一。