如果报错:
org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
1、注意先后顺序
context:annotation-config/>
<context:component-scan base-package=""/>
<tx:annotation-driven />
2、注意base-package的扫描要独立分开,不要全路径的扫描。
service部分
<context:annotation-config/>
<context:component-scan base-package="com.saper.tutorial.service"/>
<context:component-scan base-package="com.saper.tutorial.dao"/>
<tx:annotation-driven transaction-manager="transactionManager"/>
controller部分
<context:component-scan base-package="com.saper.tutorial.controller"/>
红色部分不能简写成如下:
<context:component-scan base-package="com.saper.tutorial"/>
红色部分不能简写成如下:
<context:component-scan base-package="com.saper.tutorial"/>