|
@@ -13,6 +13,7 @@ import javassist.ClassPool;
|
|
|
import javassist.CtClass;
|
|
|
import javassist.CtMethod;
|
|
|
import javassist.CtNewMethod;
|
|
|
+import javassist.LoaderClassPath;
|
|
|
import javassist.NotFoundException;
|
|
|
import lombok.NonNull;
|
|
|
import org.apache.ibatis.parsing.XNode;
|
|
@@ -41,8 +42,10 @@ public abstract class MybatisConfigureInterceptor {
|
|
|
public synchronized static void initialize() {
|
|
|
if (!INITIALIZED) {
|
|
|
try {
|
|
|
- initializeMapperListener();
|
|
|
- initializeTableInfoListener();
|
|
|
+ ClassPool pool = ClassPool.getDefault();
|
|
|
+ pool.appendClassPath(new LoaderClassPath(Thread.currentThread().getContextClassLoader()));
|
|
|
+ initializeMapperListener(pool);
|
|
|
+ initializeTableInfoListener(pool);
|
|
|
INSTANCES = Lists.newArrayList(initializeInterceptorInstances());
|
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
@@ -55,11 +58,10 @@ public abstract class MybatisConfigureInterceptor {
|
|
|
/**
|
|
|
* 初始化Mapper解析监听器
|
|
|
*
|
|
|
+ * @param pool 类对象池
|
|
|
* @throws Exception 初始化异常
|
|
|
*/
|
|
|
- private static void initializeMapperListener() throws Exception {
|
|
|
- ClassPool pool = ClassPool.getDefault();
|
|
|
-
|
|
|
+ private static void initializeMapperListener(ClassPool pool) throws Exception {
|
|
|
// 替换XMLMapperBuilder.parse方法逻辑,加入Mapper解析监听回调逻辑
|
|
|
CtClass clazz = pool.get("org.apache.ibatis.builder.xml.XMLMapperBuilder");
|
|
|
CtMethod method = clazz.getDeclaredMethod("parse");
|
|
@@ -81,11 +83,10 @@ public abstract class MybatisConfigureInterceptor {
|
|
|
/**
|
|
|
* 初始化数据模型表信息监听器
|
|
|
*
|
|
|
+ * @param pool 类对象池
|
|
|
* @throws Exception 初始化异常
|
|
|
*/
|
|
|
- private static void initializeTableInfoListener() throws Exception {
|
|
|
- ClassPool pool = ClassPool.getDefault();
|
|
|
-
|
|
|
+ private static void initializeTableInfoListener(ClassPool pool) throws Exception {
|
|
|
// 获取原始initTableFields方法
|
|
|
CtMethod initTableFields = null;
|
|
|
CtClass clazz = pool.get("com.baomidou.mybatisplus.core.metadata.TableInfoHelper");
|