@wenshao
com.alibaba.druid.util.MySqlUtils中的createXAConnection方法添加一个分支判断(直接拷贝==6的情况,并稍作修改),暂时可以解决报错,并且XA事务也可正常使用了:
`
if (major == 6) {
....
}else if (major == 8) {
if (method_6_getValue == null && !method_6_getValue_error) {
try {
class_6_connection = Class.forName("com.mysql.cj.jdbc.JdbcConnection");
method_6_getPropertySet = class_6_connection.getMethod("getPropertySet");
method_6_getBooleanReadableProperty = Class.forName("com.mysql.cj.conf.PropertySet").getMethod("getBooleanReadableProperty", String.class);
method_6_getValue = Class.forName("com.mysql.cj.conf.ReadableProperty").getMethod("getValue");
} catch (Exception ex) {
ex.printStackTrace();
method_6_getValue_error = true;
}
}
try {
// pinGlobalTxToPhysicalConnection
boolean pinGlobTx = (Boolean) method_6_getValue.invoke(
method_6_getBooleanReadableProperty.invoke(
method_6_getPropertySet.invoke(physicalConn)
, "pinGlobalTxToPhysicalConnection"
)
);
if (pinGlobTx) {
try {
if (method_6_getInstance == null && !method_6_getInstance_error) {
class_6_suspendableXAConnection = Class.forName("com.mysql.cj.jdbc.SuspendableXAConnection");
method_6_getInstance = class_6_suspendableXAConnection.getDeclaredMethod("getInstance", class_6_connection);
method_6_getInstance.setAccessible(true);
}
} catch (Throwable ex) {
ex.printStackTrace();
method_6_getInstance_error = true;
}
return (XAConnection) method_6_getInstance.invoke(null, physicalConn);
} else {
try {
if (method_6_getInstanceXA == null && !method_6_getInstanceXA_error) {
class_6_JDBC4SuspendableXAConnection = Class.forName("com.mysql.cj.jdbc.MysqlXAConnection");
method_6_getInstanceXA = class_6_JDBC4SuspendableXAConnection.getDeclaredMethod("getInstance", class_6_connection, boolean.class);
method_6_getInstanceXA.setAccessible(true);
}
} catch (Throwable ex) {
ex.printStackTrace();
method_6_getInstanceXA_error = true;
}
return (XAConnection) method_6_getInstanceXA.invoke(null, physicalConn, Boolean.FALSE);
}
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
}
} catch (Exception e) {
e.printStackTrace();
method_6_getInstance_error = true;
}
}
`