浏览代码

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

nieqiuqiu 5 年之前
父节点
当前提交
95f18bfc32

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

@@ -198,7 +198,7 @@ public class MybatisPlusAutoConfiguration implements InitializingBean {
             factory.setTypeEnumsPackage(this.properties.getTypeEnumsPackage());
         }
         // TODO 此处必为非 NULL
-        GlobalConfig globalConfig = this.properties.getGlobalConfig();
+        GlobalConfig globalConfig = Optional.ofNullable(this.properties.getGlobalConfig()).orElse(factory.getConfiguration().getGlobalConfig());
         // TODO 注入填充器
         if (this.applicationContext.getBeanNamesForType(MetaObjectHandler.class,
             false, false).length > 0) {

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

@@ -114,7 +114,14 @@ public class MybatisPlusProperties {
      * TODO 全局配置
      */
     @NestedConfigurationProperty
-    private GlobalConfig globalConfig = GlobalConfigUtils.defaults();
+    private GlobalConfig globalConfig;
+
+    public GlobalConfig getGlobalConfig() {
+        if (globalConfig == null) {
+            globalConfig = GlobalConfigUtils.defaults();
+        }
+        return globalConfig;
+    }
 
 
     public Resource[] resolveMapperLocations() {

+ 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;
     }
 
+    public MybatisConfiguration getConfiguration(){
+        return this.configuration;
+    }
+
     /**
      * Set locations of MyBatis mapper files that are going to be merged into the {@code SqlSessionFactory} configuration
      * at runtime.