Spring 自動注入失敗異常

cuixiaoming1994發表於2018-03-27

在DAO層中使用了HibernateTemplate注入
報錯資訊如下

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerDao': Injection of autowired dependencies failed; 
nested exception is org.springframework.beans.factory.
BeanCreationException: Could not autowire field: private org.springframework.orm.hibernate3.HibernateTemplate com.cuixiaoming.dao.impl.CustomerDaoImpl.hibernateTemplate; 
nested exception is org.springframework.beans.factory.
NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.orm.hibernate3.HibernateTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. 
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

自動注入失敗Injection of autowired dependencies failed
我按照百度上部落格的方法,檢查了包掃描,web.xml,註解 都沒有發生錯誤

看了好半天,最後終於發現

導包倒錯了!!!!!!!

dao層程式碼裡面自動提示寫的是hibernate3

import org.springframework.orm.hibernate3.HibernateTemplate;

配置中是hibernate5

org.springframework.orm.hibernate5.HibernateTemplate

使用Hibernate的時候一定要切記導包問題啊

相關文章