Cannot unwrap to requested type [javax.sql.DataSource]

遇上这个bug我的情况是这样,hibernate4以后,spring3.1不再有hibernateDaoSupport,在dao层不能继承HibernateDaoSupport,

只能显式声明SessionFactory,并且设置get/set方法。

不确定的说:

       在hibernate4以后,session管理变动较大,spring也变了,所以DataSource要在applicationContext.xml里面配置

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

<property name="dataSource" ref="dataSource"/>

...

</bean>

如果你在hibernate.cfg.xml里面配置了,就会报出Cannot unwrap to requested type [javax.sql.DataSource]错误。

原文地址:https://www.cnblogs.com/suizhikuo/p/3618625.html