您的位置:首页 > 编程语言 > Java开发

hibernate与Spring整合时出现错误org.springframework.beans.factory.BeanCreationException: Error creating bean

2017-03-30 20:54 615 查看
hibernate与Spring整合时出现错误:

org.springframework.beans.factory.BeanCreationException:Error creating bean with name 'sessionFactory' defined in class path resource[applicationContext.xml]: Instantiation of bean failed; nested exception isorg.springframework.beans.BeanInstantiationException:
Could not instantiatebean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]:Constructor threw exception; nested exception is java.lang.NoSuchMethodError:org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder;

                    atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:883)

                    atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839)

                    atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)

                    atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)

                    atjava.security.AccessController.doPrivileged(Native Method)

                    atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)

                    atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)

                    atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)

                    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)

                    atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)

                    atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)

                    atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)

                    atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)

                    atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)

                    atorg.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)

                    atorg.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)

                    atcn.my.oa.test.SpringTest.<init>(SpringTest.java:13)

                    atsun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

                    atsun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

                    atsun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

                    atjava.lang.reflect.Constructor.newInstance(Constructor.java:525)

                    atorg.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:195)

                    atorg.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:244)

                    atorg.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

                    atorg.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:241)

                    atorg.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)

                    atorg.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)

                    atorg.junit.runners.ParentRunner$3.run(ParentRunner.java:238)

                    atorg.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)

                    atorg.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)

                    atorg.junit.runners.ParentRunner.access$000(ParentRunner.java:53)

                    atorg.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)

                    atorg.junit.runners.ParentRunner.run(ParentRunner.java:309)

                    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

                    atorg.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

                    atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)

                    atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)

                    atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)

                    atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Caused by:org.springframework.beans.BeanInstantiationException: Could not instantiatebean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]:Constructor threw exception; nested exception is java.lang.NoSuchMethodError:org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder;

                    atorg.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:115)

                    atorg.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61)

                    atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:877)

                    ... 38 more

Caused by:java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder;

                    atorg.slf4j.LoggerFactory.bind(LoggerFactory.java:121)

                    atorg.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)

                    atorg.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:268)

                    atorg.slf4j.LoggerFactory.getLogger(LoggerFactory.java:241)

                    atorg.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254)

                    atorg.hibernate.cfg.Configuration.<clinit>(Configuration.java:196)

                    atjava.lang.Class.forName0(Native Method)

                    at java.lang.Class.forName(Class.java:186)

                    atorg.springframework.orm.hibernate3.LocalSessionFactoryBean.class$(LocalSessionFactoryBean.java:174)

                    atorg.springframework.orm.hibernate3.LocalSessionFactoryBean.<init>(LocalSessionFactoryBean.java:174)

                    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(NativeMethod)

                    atsun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

                    atsun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

                    atjava.lang.reflect.Constructor.newInstance(Constructor.java:525)

                    atorg.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100)

                    ... 40 more

缺少jar包;slf4j-log4j12-1.6.1.jar
加入后还是有错误:

SLF4J: slf4j-api 1.6.x (or later)is incompatible with this binding.
SLF4J: Your binding is version 1.5.5or earlier.
SLF4J: Upgrade your binding toversion 1.6.x. or 2.0.x
因为我当时加入的slf4j-api-1.6.1.jar是1.6,而slf4j-log4j12-1.6.1.jar最开始我加入的是:slf4j-log4j12-1.5.0.jar
所以出现以下错误
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  hibernate bean Spring
相关文章推荐