SpringMVC @Transactional的陷井大坑引發No Session found for current thread
一、TransactionManager事務配置
(1)註解配置
配置spring的xml加@Transactional<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
(2)xml配置
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" read-only="true" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update" propagation="REQUIRED" />
<tx:method name="delete" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
<aop:pointcut expression="execution(public * com.mk.dao.impl.*.*(..))" id="servicePointcut" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="servicePointcut" />
</aop:config>
二、@Transactional
(1)事務使用jdk介面動態代理
暫無
(2)事務使用CGLIB類代理
需要設定spring的xml配置proxy-target-class="true"
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
1.大坑
@Transactional註解的類無法賦予繼承的方法事務
如:
public abstract class Service<T extends Serializable,D extends Dao<T>> implements IService<T> {
protected D dao;
@Autowired
public void setDao(D dao) {
this.dao = dao;
}
//@Transactional
@Override
public T get(Integer id) {
if(Utils.isNull(id))
return null;
return dao.get(id);
}
}
@Transactional
@org.springframework.stereotype.Service
public class UserService extends Service<User, UserDao> {
}
即在呼叫UserService的get方法時會丟擲No Session found for current thread異常
2.中坑
@Transactional註解在介面或介面的方法,事務失效,CGLIB無法從繼承中獲取Transactional註解
3.小坑
@Transactional註解在public方法才有效,其他protected等方法都不起事務作用
相關文章
- Could not obtain transaction-synchronized Session for current thread原因及解決方案AIsynchronizedSessionthread
- 異常資訊解決:Could not obtain transaction-synchronized Session for current threadAIsynchronizedSessionthread
- ORA-01623: log is current log for thread - cannot dropthread
- Maven - No plugin found for prefix 'war' in the current project and in the plugin groupsMavenPluginProject
- 如何區分 Connection、Thread和SessionthreadSession
- Oracle DBLink bug引發的故障(Session Hang Memory leak)OracleSession
- SpringMVC(3)-request域和session域的作用和區別SpringMVCSession
- MySQL:一個innodb_thread_concurrency設定不當引發的故障MySqlthread
- SpringMVC請求引數解析SpringMVC
- SpringMVC重定向傳引數的實現SpringMVC
- @Transactional
- SpringMVC實現引數校驗SpringMVC
- SpringMVC的引數繫結-日期格式轉換SpringMVC
- 拙見--springMVC的controller接受的請求引數SpringMVCController
- oracle中的processes,session,transaction引數詳解OracleSession
- spring boot 讀寫引數到sessionSpring BootSession
- C#關於在返回值為Task方法中使用Thread.Sleep引發的思考C#thread
- SpringMVC中@RequestBody接收前端傳來的多個引數SpringMVC前端
- 開發公眾號吃的大坑,今天記下來。
- 【工作篇】再次熟悉 SpringMVC 引數繫結SpringMVC
- JWT+SpringBoot+SpringMVC引數解析器JWTSpring BootSpringMVC
- Go GC 機制的大坑GoGC
- 併發-2-Thread和Runnable的APIthreadAPI
- MySQL中的CURRENT_TIMESTAMPMySql
- SpringMVC原始碼之引數解析繫結原理SpringMVC原始碼
- react-navigation的超級大坑ReactNavigation
- java併發程式設計:Thread類的使用Java程式設計thread
- SpringMvc - SpringMvc的執行流程SpringMVC
- AUTHID CURRENT_USER的注意點
- 【Spring】@Transactional 閒聊Spring
- Thread 併發執行例項thread
- 解決requests庫中session.verify引數失效的問題Session
- 7.71 CURRENT_TIMESTAMP
- 7.70 CURRENT_DATE
- SpringMVC底層——請求引數處理流程描述SpringMVC
- 一篇文章搞定SpringMVC引數繫結SpringMVC
- 併發程式設計Thread的常用API有哪些?程式設計threadAPI
- 內部呼叫@Transactional 註解的方法