Explorar el Código

发布3.5.5-SNAPSHOT.

nieqiurong hace 1 año
padre
commit
9da6eef48e

+ 1 - 0
changelog-temp.md

@@ -0,0 +1 @@
+* fix: 修复Aop增强Mapper层导致的转换错误.

+ 1 - 1
gradle.properties

@@ -1,4 +1,4 @@
-APP_VERSION=3.5.4
+APP_VERSION=3.5.5-SNAPSHOT
 APP_GROUP=com.baomidou
 signing.keyId=1FD337F9
 signing.password=243194995

+ 5 - 13
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/service/impl/ServiceImpl.java

@@ -59,17 +59,6 @@ import java.util.function.Function;
 @SuppressWarnings("unchecked")
 public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {
 
-    private static boolean loadAop = false;
-
-    static {
-        try {
-            ClassUtils.toClassConfident("org.springframework.aop.framework.AopProxyUtils");
-            loadAop = true;
-        } catch (Exception exception) {
-            // ignore
-        }
-    }
-
     private final ConversionService conversionService = DefaultConversionService.getSharedInstance();
 
     protected final Log log = LogFactory.getLog(getClass());
@@ -101,8 +90,11 @@ public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {
             synchronized (this) {
                 if (this.sqlSessionFactory == null) {
                     Object target = this.baseMapper;
-                    if (loadAop && AopUtils.isAopProxy(this.baseMapper)) {
-                        target = AopProxyUtils.getSingletonTarget(this.baseMapper);
+                    // 这个检查目前看着来说基本上可以不用判断Aop是不是存在了.
+                    if (com.baomidou.mybatisplus.extension.toolkit.AopUtils.isLoadSpringAop()) {
+                        if (AopUtils.isAopProxy(this.baseMapper)) {
+                            target = AopProxyUtils.getSingletonTarget(this.baseMapper);
+                        }
                     }
                     if (target != null) {
                         MybatisMapperProxy mybatisMapperProxy = (MybatisMapperProxy) Proxy.getInvocationHandler(target);

+ 27 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/toolkit/AopUtils.java

@@ -30,8 +30,35 @@ import java.lang.reflect.Field;
  */
 public class AopUtils {
 
+    /**
+     * 是否加载Spring-Aop模块
+     *
+     * @since 3.5.4
+     */
+    private static boolean loadAop = false;
+
+    static {
+        try {
+            ClassUtils.toClassConfident("org.springframework.aop.framework.AopProxyUtils");
+            loadAop = true;
+        } catch (Exception exception) {
+            // ignore
+        }
+    }
+
     private static final Log logger = LogFactory.getLog(AopUtils.class);
 
+    /**
+     * 是否加载Spring-Aop模块
+     *
+     * @return 是否加载Spring-Aop模块
+     * @since 3.5.5
+     */
+    public static boolean isLoadSpringAop() {
+        return loadAop;
+    }
+
+
     /**
      * 获取源目标对象
      *