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 threadAIsynchronizedSessionthread
- Could not obtain transaction-synchronized Session for current thread原因及解決方案AIsynchronizedSessionthread
- 錯誤記錄(九)Could not obtain transaction-synchronized Session for current threadAIsynchronizedSessionthread
- makes the current sessionSession
- 解決SpringMVC+Hibernate錯誤: No Hibernate Session bound to threadSpringMVCSessionthread
- AUDIT IN SESSION CURRENT無法NOAUDITSession
- 【SESSION】v$session and v$license 中sessions_current 的區別Session
- Maven - No plugin found for prefix 'war' in the current project and in the plugin groupsMavenPluginProject
- No Hibernate Session bound to threadSessionthread
- hibernate.current_session_context_classSessionContext
- AUTHID DEFINER\authid current_user與alter session set current_schemaSession
- Monitor RDBMS Session UGA and PGA Current And Maximum Usage Over TimeSession
- ORA-00322: log 3 of thread 1 is not current copythread
- ORA-01623: log is current log for thread - cannot dropthread
- 如何區分 Connection、Thread和SessionthreadSession
- Oracle DBLink bug引發的故障(Session Hang Memory leak)OracleSession
- mybatis一級快取(session cache)引發的問題MyBatis快取Session
- @Transactional
- 【案例】常駐查詢引發的thread pool 效能問題之二thread
- 【案例】常駐查詢引發的thread pool 效能問題之一thread
- SpringMVC - controller中獲取sessionSpringMVCControllerSession
- OGG - No Valid Default Archive Destination Directory Found for Thread #Hivethread
- springmvc 引數繫結SpringMVC
- Scheduler&Task&Worker&Thread&Request&Session&Connection OF MSSQLthreadSessionSQL
- PHP中如何保持SESSION以及由此引發的一些思考PHPSession
- 查詢gv$session引發大量的PX Deq Credit: send blkd事件Session事件
- MySQL:一個innodb_thread_concurrency設定不當引發的故障MySqlthread
- oracle中的processes,session,transaction引數OracleSession
- SpringMVC(3)-request域和session域的作用和區別SpringMVCSession
- SpringMVC請求引數解析SpringMVC
- SpringMVC之引數傳遞SpringMVC
- SpringMVC中的引數繫結總結SpringMVC
- SpringMVC重定向傳引數的實現SpringMVC
- 引數SESSION_CACHED_CURSORSSession
- innodb_thread_concurrency引數的建議配置thread
- 開發公眾號吃的大坑,今天記下來。
- springMVC中引數格式化SpringMVC
- SpringMVC實現引數校驗SpringMVC