Browse Source

解决GlobalConfig在ConfigurationCustomizer不生效的问题.

nieqiuqiu 5 năm trước cách đây
mục cha
commit
e36a3853ec

+ 2 - 1
mybatis-plus-boot-starter/src/main/java/com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.java

@@ -198,7 +198,8 @@ public class MybatisPlusAutoConfiguration implements InitializingBean {
             factory.setTypeEnumsPackage(this.properties.getTypeEnumsPackage());
             factory.setTypeEnumsPackage(this.properties.getTypeEnumsPackage());
         }
         }
         // TODO 此处必为非 NULL
         // TODO 此处必为非 NULL
-        GlobalConfig globalConfig = this.properties.getGlobalConfig();
+        // config的优先级要大于properties
+        GlobalConfig globalConfig = factory.getConfiguration().hasGlobalConfig() ? factory.getConfiguration().getGlobalConfig() : this.properties.getGlobalConfig();
         // TODO 注入填充器
         // TODO 注入填充器
         if (this.applicationContext.getBeanNamesForType(MetaObjectHandler.class,
         if (this.applicationContext.getBeanNamesForType(MetaObjectHandler.class,
             false, false).length > 0) {
             false, false).length > 0) {

+ 1 - 2
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisConfiguration.java

@@ -21,7 +21,6 @@ import com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor;
 import com.baomidou.mybatisplus.core.executor.MybatisReuseExecutor;
 import com.baomidou.mybatisplus.core.executor.MybatisReuseExecutor;
 import com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor;
 import com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor;
 import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils;
 import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils;
-import lombok.Getter;
 import lombok.Setter;
 import lombok.Setter;
 import org.apache.ibatis.binding.MapperRegistry;
 import org.apache.ibatis.binding.MapperRegistry;
 import org.apache.ibatis.executor.Executor;
 import org.apache.ibatis.executor.Executor;
@@ -60,7 +59,7 @@ public class MybatisConfiguration extends Configuration {
         return globalConfig;
         return globalConfig;
     }
     }
 
 
-    public boolean hasGlobalConfig(){
+    public boolean hasGlobalConfig() {
         return globalConfig != null;
         return globalConfig != null;
     }
     }
 
 

+ 4 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/spring/MybatisSqlSessionFactoryBean.java

@@ -323,6 +323,10 @@ public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFacto
         this.configuration = configuration;
         this.configuration = configuration;
     }
     }
 
 
+    public MybatisConfiguration getConfiguration(){
+        return this.configuration;
+    }
+
     /**
     /**
      * Set locations of MyBatis mapper files that are going to be merged into the {@code SqlSessionFactory} configuration
      * Set locations of MyBatis mapper files that are going to be merged into the {@code SqlSessionFactory} configuration
      * at runtime.
      * at runtime.