org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name'sessionFactory' defined in class path resource [applicationContext.xml]: Unsatisfied dependency expressed through bean property 'eventListeners': : Error creating bean with name 'hibernateTemplate' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sessionFactory': FactoryBean which is currently in creation returned null from getObject; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateTemplate' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sessionFactory': FactoryBean which is currently in creation returned null from getObject
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateTemplate' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sessionFactory': FactoryBean which is currently in creation returned null from getObject
以上错误出现原因,我在applicationContext.xml声明部分设置了default-autowire="byType"
解决办法: 去掉设置。让其默认
如图:去掉选中部分

本文分析了Spring框架中因依赖注入失败导致的UnsatisfiedDependencyException异常,并提供了解决方案。问题出现在applicationContext.xml配置文件中,由于设置了不合适的自动装配选项导致Hibernate Template无法正确引用SessionFactory。
861

被折叠的 条评论
为什么被折叠?



