题目:org.springframework.beans.factory.BeanCreationException异常产生的原因和解决方案。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext
resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError:
org/apache/commons/pool/impl/GenericObjectPool
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getDeclaredConstructor(Unknown Source)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate
(SimpleInstantiationStrategy.java:54)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean
(AbstractAutowireCapableBeanFactory.java:752)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance
(AbstractAutowireCapableBeanFactory.java:717)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean
(AbstractAutowireCapableBeanFactory.java:386)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton
(DefaultSingletonBeanRegistry.java:155)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons
(DefaultListableBeanFactory.java:291)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:245)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:188)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:987)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:909)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:495)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1206)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2009-10-28 16:14:57 org.apache.catalina.core.Standa啊ror listenerStart
该异常产生的原因:
是因为在将spring框架和hibernate框架进行整合的时候,包冲突所引起的,这个bug在myeclipse6.0的时候就开始产生了,产生冲突的两
个.jar文件是:asm.jar和asm-2.2.3.jar的冲突造成的。
解决方案:视频上说删除asm-2.2.3.jar即可正常运行!
但是我在我的机器删除了以后,却一直还是报上面的错:org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean
failed; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool
后来我去我的lib目录下又删除了很多的名字相似的.jar文件(删除了能有5,6个.jar文件)但是还是报上面的错,刺激了!
下一步又去接着看视频,寻找蛛丝马迹,突然发现我用的是myeclipse6.1,hibernate只支持到3.1,而视频上用的是myeclipse6.5,支持到
hibernate3.2,所以就去网上下载了myeclipse6.5,安装后,又新建了一个项目,将前面项目的相关文件都给拷贝过来(因为.jar文件不同,所
以前面那个项目是不能直接用了),又部署了项目以后,果然是高版本的功能全,报的错都比较有针对性!
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in
ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is
java.io.FileNotFoundException: class path resource [com.oristand.bean.User.hbm.xml] cannot be opened because it does not
exist
Caused by: java.io.FileNotFoundException: class path resource [com.oristand.bean.User.hbm.xml] cannot be opened because it
does not exist
分析错误才发现是:
<property name="mappingResources">
<list>
<value>com.oristand.bean.User.hbm.xml</value>
</list>
</property>
改为:
<property name="mappingResources">
<list>
<value>com/oristand/bean/User.hbm.xml</value>
</list>
</property>
再次部署运行:又出现下面的错,更刺激了:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in
ServletContext resource [/WEB-INF/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;)V
这时候再删除相应的asm-2.2.3.jar,再次部署运行,
成功了!!!!!!!!!!!!!!!!!!!!!!