题目:org.springframework.beans.factory.BeanCreationException(hibernate中的jar包和spring中的jar包冲突)异常产生的原因和解决方案。

题目: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,再次部署运行,

成功了!!!!!!!!!!!!!!!!!!!!!!

 

 

 

引入一个依赖后,启动springboot报错:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultValidator' defined in class path resource [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.hibernate.validator.engine.ConfigurationImpl.getDefaultParameterNameProvider()Ljavax/validation/ParameterNameProvider; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:893) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
06-08
评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值