集成spring的事务后Trans无法使用,但是在读写分离的判断中需要获取是否在事务中,那么需要怎么获取?
public void run(DataSource dataSource, ConnCallback callback) {
DataSource selectDataSource = selectDataSource(Trans.get(),dataSource,callback);
Connection con = DataSourceUtils.getConnection(selectDataSource);
try {
callback.invoke(con);
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
throw new RuntimeException(e);
}
} finally {
DataSourceUtils.releaseConnection(con, dataSource);
}
}