nieqiuqiu 5 tahun lalu
induk
melakukan
da368d94dc

+ 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 =  factory.getConfiguration().getGlobalConfig();
+        GlobalConfig globalConfig = this.properties.getGlobalConfig();
         // TODO 注入填充器
         if (this.applicationContext.getBeanNamesForType(MetaObjectHandler.class, false, false).length > 0) {
             MetaObjectHandler metaObjectHandler = this.applicationContext.getBean(MetaObjectHandler.class);

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

@@ -16,7 +16,9 @@
 package com.baomidou.mybatisplus.autoconfigure;
 
 import com.baomidou.mybatisplus.core.MybatisConfiguration;
+import com.baomidou.mybatisplus.core.config.GlobalConfig;
 import com.baomidou.mybatisplus.core.toolkit.Constants;
+import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils;
 import lombok.Data;
 import lombok.experimental.Accessors;
 import org.apache.ibatis.scripting.LanguageDriver;
@@ -108,6 +110,12 @@ public class MybatisPlusProperties {
      */
     private String typeEnumsPackage;
 
+    /**
+     * TODO 全局配置
+     */
+    @NestedConfigurationProperty
+    private GlobalConfig globalConfig = GlobalConfigUtils.defaults();
+
 
     public Resource[] resolveMapperLocations() {
         return Stream.of(Optional.ofNullable(this.mapperLocations).orElse(new String[0]))

+ 21 - 105
mybatis-plus-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json

@@ -10,127 +10,43 @@
             "name": "mybatis-plus.configuration",
             "sourceMethod": "getConfiguration()",
             "type": "com.baomidou.mybatisplus.core.MybatisConfiguration"
-        }
-    ],
-    "properties": [
-        {
-            "name": "mybatis-plus.configuration.global-config.banner",
-            "type": "java.lang.Boolean",
-            "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig"
-        },
-        {
-            "name": "mybatis-plus.configuration.global-config.db-config.capital-mode",
-            "type": "java.lang.Boolean",
-            "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig"
-        },
-        {
-            "name": "mybatis-plus.configuration.global-config.db-config.column-format",
-            "type": "java.lang.String",
-            "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig"
-        },
-        {
-            "name": "mybatis-plus.configuration.global-config.db-config.id-type",
-            "type": "com.baomidou.mybatisplus.annotation.IdType",
-            "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig"
-        },
-        {
-            "name": "mybatis-plus.configuration.global-config.db-config.insert-strategy",
-            "type": "com.baomidou.mybatisplus.annotation.FieldStrategy",
-            "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig"
-        },
-        {
-            "name": "mybatis-plus.configuration.global-config.db-config.logic-delete-field",
-            "type": "java.lang.String",
-            "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig"
-        },
-        {
-            "name": "mybatis-plus.configuration.global-config.db-config.logic-delete-value",
-            "type": "java.lang.String",
-            "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig"
-        },
-        {
-            "name": "mybatis-plus.configuration.global-config.db-config.logic-not-delete-value",
-            "type": "java.lang.String",
-            "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig"
-        },
-        {
-            "name": "mybatis-plus.configuration.global-config.db-config.property-format",
-            "type": "java.lang.String",
-            "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig"
-        },
-        {
-            "name": "mybatis-plus.configuration.global-config.db-config.schema",
-            "type": "java.lang.String",
-            "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig"
-        },
-        {
-            "name": "mybatis-plus.configuration.global-config.db-config.select-strategy",
-            "type": "com.baomidou.mybatisplus.annotation.FieldStrategy",
-            "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig"
-        },
-        {
-            "name": "mybatis-plus.configuration.global-config.db-config.table-prefix",
-            "type": "java.lang.String",
-            "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig"
-        },
-        {
-            "name": "mybatis-plus.configuration.global-config.db-config.table-underline",
-            "type": "java.lang.Boolean",
-            "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig"
-        },
-        {
-            "name": "mybatis-plus.configuration.global-config.db-config.update-strategy",
-            "type": "com.baomidou.mybatisplus.annotation.FieldStrategy",
-            "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig"
-        },
-        {
-            "name": "mybatis-plus.configuration.global-config.enable-sql-runner",
-            "type": "java.lang.Boolean",
-            "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig"
         },
         {
-            "name": "mybatis-plus.configuration.global-config.mapper-registry-cache",
-            "type": "java.util.Set<java.lang.String>",
-            "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig"
+            "sourceType": "com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties",
+            "name": "mybatis-plus.global-config",
+            "sourceMethod": "getGlobalConfig()",
+            "type": "com.baomidou.mybatisplus.core.config.GlobalConfig"
         },
         {
-            "name": "mybatis-plus.configuration.global-config.super-mapper-class",
-            "type": "java.lang.Class<?>",
-            "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig"
-        },
+            "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig",
+            "name": "mybatis-plus.global-config.db-config",
+            "sourceMethod": "getDbConfig()",
+            "type": "com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig"
+        }
+    ],
+    "properties": [
         {
             "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig",
-            "name": "mybatis-plus.configuration.global-config.meta-object-handler",
+            "name": "mybatis-plus.global-config.meta-object-handler",
             "deprecation": {
-                "level": "error"
+                "level": "error",
+                "reason": "3.0开始废除此属性,请使用@Bean的方式注入至Spring容器."
             }
         },
-        {
-            "name": "mybatis-plus.configuration.global-config.datacenter-id",
-            "type": "java.lang.Long",
-            "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig",
-            "deprecated": true,
-            "deprecation": {}
-        },
-        {
-            "name": "mybatis-plus.configuration.global-config.worker-id",
-            "type": "java.lang.Long",
-            "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig",
-            "deprecated": true,
-            "deprecation": {}
-        },
         {
             "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig",
-            "name": "mybatis-plus.configuration.global-config.db-config.key-generator",
+            "name": "mybatis-plus.global-config.db-config.key-generator",
             "deprecation": {
-                "level": "error"
+                "level": "error",
+                "reason": "3.0开始废除此属性,请使用@Bean的方式注入至Spring容器."
             }
         },
         {
             "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig",
-            "name": "mybatis-plus.configuration.global-config.sql-injector",
+            "name": "mybatis-plus.global-config.sql-injector",
             "deprecation": {
-                "level": "error"
+                "level": "error",
+                "reason": "3.0开始废除此属性,请使用@Bean的方式注入至Spring容器."
             }
         },
         {
@@ -162,7 +78,7 @@
         },
         {
             "sourceType": "com.baomidou.mybatisplus.core.config.GlobalConfig",
-            "name": "mybatis-plus.configuration.global-config.id-generator",
+            "name": "mybatis-plus.global-config.id-generator",
             "deprecation": {
                 "level": "error"
             }

+ 1 - 1
mybatis-plus-boot-starter/src/test/java/com/baomidou/mybatisplus/starter/MetadataTest.java

@@ -70,7 +70,7 @@ class MetadataTest {
         Map<String, Metadata> metadataMap = properties.stream().map(map -> new Metadata(map.get("name"), map.get("type"), map.get("sourceType"))).collect(Collectors.toMap(Metadata::getName, metadata -> metadata));
         Assertions.assertEquals(metadataMap.get("mybatis-plus.type-enums-package"), new Metadata("mybatis-plus.type-enums-package", String.class.getName(), MybatisPlusProperties.class.getName()));
         Assertions.assertEquals(metadataMap.get("mybatis-plus.type-aliases-package"), new Metadata("mybatis-plus.type-aliases-package", String.class.getName(), MybatisPlusProperties.class.getName()));
-        Assertions.assertEquals(metadataMap.get("mybatis-plus.configuration.global-config.db-config.table-underline"), new Metadata("mybatis-plus.configuration.global-config.db-config.table-underline", Boolean.class.getName(), GlobalConfig.DbConfig.class.getName()));
+        Assertions.assertEquals(metadataMap.get("mybatis-plus.global-config.db-config.table-underline"), new Metadata("mybatis-plus.global-config.db-config.table-underline", Boolean.class.getName(), GlobalConfig.DbConfig.class.getName()));
         Assertions.assertEquals(metadataMap.get("mybatis-plus.config-location"), new Metadata("mybatis-plus.config-location", String.class.getName(), MybatisPlusProperties.class.getName()));
         Assertions.assertEquals(metadataMap.get("mybatis-plus.configuration.call-setters-on-nulls"), new Metadata("mybatis-plus.configuration.call-setters-on-nulls", Boolean.class.getName(), MybatisConfiguration.class.getName()));
         Assertions.assertEquals(metadataMap.get("mybatis-plus.configuration.jdbc-type-for-null"), new Metadata("mybatis-plus.configuration.jdbc-type-for-null", JdbcType.class.getName(), MybatisConfiguration.class.getName()));

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

@@ -49,15 +49,15 @@ public class MybatisConfiguration extends Configuration {
      */
     protected final MybatisMapperRegistry mybatisMapperRegistry = new MybatisMapperRegistry(this);
 
-    @Setter
-    @Getter
-    private GlobalConfig globalConfig = GlobalConfigUtils.defaults();
-
     public MybatisConfiguration(Environment environment) {
         this();
         this.environment = environment;
     }
 
+    @Setter
+    @Getter
+    private GlobalConfig globalConfig = GlobalConfigUtils.defaults();
+
     /**
      * 初始化调用
      */