在搭建SSH框架時遇到這個問題,我把DataSource的配置內容放到了hibernate.cfg.xml裏,開始沒有定義Hibernate的事務管理器HibernateTransactionManager時,沒有什麼問題,但是一定義HibernateTransactionManager,就報上面這個錯誤,搞了半天搞不好,無論怎麼去改動去設置都還是報錯,但是複製一個把DataSource定義在applicationContext.xml裏的過來就沒什麼問題,後來網上搜,看別人說可能是下面的解釋情況。
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]錯誤。
原文地址:點擊打開鏈接