'hibernateTemplate' must be of type [org.springframework.orm.hibernate5.HibernateTemplate]

‘hibernateTemplate’ must be of type [org.springframework.orm.hibernate5.HibernateTemplate], but was actually of type [org.springframework.orm.hibernate3.HibernateTemplate]

详细错误提示如下:

警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userDao’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named ‘hibernateTemplate’ must be of type [org.springframework.orm.hibernate5.HibernateTemplate], but was actually of type [org.springframework.orm.hibernate3.HibernateTemplate]

解决方法:将beans.xml文件中用的Class所在的包和引用HibernateTemplate中的类中引入的包一致即可。

例如:在beans.xml文件中使用hibernate5(class=”org.springframework.orm.hibernate5.HibernateTemplate”)

<bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
    <property name="sessionFactory" ref="sessionFactory"></property>
</bean>

则在所有使用HibernateTemplate类均引用hibernate5:

import org.springframework.orm.hibernate5.HibernateTemplate;

你可能感兴趣的:(spring,exception,Hibernate)