You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2021/08/07 09:19:38 UTC

[shardingsphere] branch master updated: Move schema name parameter signature of ShardingSphereDataSourceFactory and GovernanceShardingSphereDataSourceFactory (#11694)

This is an automated email from the ASF dual-hosted git repository.

menghaoran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 1c15288  Move schema name parameter signature of ShardingSphereDataSourceFactory and GovernanceShardingSphereDataSourceFactory (#11694)
1c15288 is described below

commit 1c1528828d9934a77aac0637c0ec4b55505dec37
Author: Liang Zhang <te...@163.com>
AuthorDate: Sat Aug 7 17:19:10 2021 +0800

    Move schema name parameter signature of ShardingSphereDataSourceFactory and GovernanceShardingSphereDataSourceFactory (#11694)
    
    * Move schema name parameter signature of GovernanceShardingSphereDataSourceFactory
    
    * Refactor YamlGovernanceShardingSphereDataSourceFactory
    
    * Move schema name parameter signature of ShardingSphereDataSourceFactory
    
    * Move schema name parameter signature of ShardingSphereDataSourceFactory
    
    * Fix spring boot starter
---
 .../api/ShardingSphereDataSourceFactory.java       | 37 +++++++++----------
 .../yaml/YamlShardingSphereDataSourceFactory.java  | 30 ++++++++--------
 .../core/datasource/ShardingSphereDataSource.java  | 12 +++----
 .../api/ShardingSphereDataSourceFactoryTest.java   |  4 +--
 .../driver/jdbc/adapter/WrapperAdapterTest.java    |  2 +-
 .../datasource/ShardingSphereDataSourceTest.java   |  2 +-
 .../UnsupportedOperationDataSourceTest.java        |  2 +-
 .../GovernanceShardingSphereDataSourceFactory.java | 27 +++++++-------
 ...lGovernanceShardingSphereDataSourceFactory.java | 42 ++++++++++------------
 .../GovernanceShardingSphereDataSource.java        | 10 +++---
 .../boot/ShardingSphereAutoConfiguration.java      |  6 ++--
 .../parser/DataSourceBeanDefinitionParser.java     | 10 +++---
 .../resources/META-INF/namespace/datasource.xsd    |  2 +-
 .../META-INF/spring/application-context.xml        |  2 +-
 .../ShardingSphereGovernanceAutoConfiguration.java | 12 +++----
 .../parser/DataSourceBeanDefinitionParser.java     | 10 +++---
 .../ShardingSphereJDBCDataSourceConfiguration.java |  5 ++-
 17 files changed, 100 insertions(+), 115 deletions(-)

diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/api/ShardingSphereDataSourceFactory.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/api/ShardingSphereDataSourceFactory.java
index 3ba9157..75cdc7f 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/api/ShardingSphereDataSourceFactory.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/api/ShardingSphereDataSourceFactory.java
@@ -26,7 +26,7 @@ import org.apache.shardingsphere.infra.database.DefaultSchema;
 import javax.sql.DataSource;
 import java.sql.SQLException;
 import java.util.Collection;
-import java.util.HashMap;
+import java.util.Collections;
 import java.util.Map;
 import java.util.Properties;
 
@@ -39,60 +39,55 @@ public final class ShardingSphereDataSourceFactory {
     /**
      * Create ShardingSphere data source.
      *
+     * @param schemaName schema name
      * @param dataSourceMap data source map
-     * @param configurations rule configurations
+     * @param configs rule configurations
      * @param props properties for data source
-     * @param schemaName schema name for configurations
      * @return ShardingSphere data source
      * @throws SQLException SQL exception
      */
-    public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final Collection<RuleConfiguration> configurations,
-                                              final Properties props, final String schemaName) throws SQLException {
-        return new ShardingSphereDataSource(dataSourceMap, configurations, props, schemaName);
+    public static DataSource createDataSource(final String schemaName, 
+                                              final Map<String, DataSource> dataSourceMap, final Collection<RuleConfiguration> configs, final Properties props) throws SQLException {
+        return new ShardingSphereDataSource(schemaName, dataSourceMap, configs, props);
     }
     
     /**
      * Create ShardingSphere data source.
      *
      * @param dataSourceMap data source map
-     * @param configurations rule configurations
+     * @param configs rule configurations
      * @param props properties for data source
      * @return ShardingSphere data source
      * @throws SQLException SQL exception
      */
-    public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final Collection<RuleConfiguration> configurations, final Properties props) throws SQLException {
-        return new ShardingSphereDataSource(dataSourceMap, configurations, props, DefaultSchema.LOGIC_NAME);
+    public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final Collection<RuleConfiguration> configs, final Properties props) throws SQLException {
+        return new ShardingSphereDataSource(DefaultSchema.LOGIC_NAME, dataSourceMap, configs, props);
     }
     
     /**
      * Create ShardingSphere data source.
      *
      * @param dataSource data source
-     * @param configurations rule configurations
+     * @param configs rule configurations
      * @param props properties for data source
      * @return ShardingSphere data source
      * @throws SQLException SQL exception
      */
-    public static DataSource createDataSource(final DataSource dataSource, final Collection<RuleConfiguration> configurations, final Properties props) throws SQLException {
-        Map<String, DataSource> dataSourceMap = new HashMap<>(1, 1);
-        dataSourceMap.put(DefaultSchema.LOGIC_NAME, dataSource);
-        return createDataSource(dataSourceMap, configurations, props, DefaultSchema.LOGIC_NAME);
+    public static DataSource createDataSource(final DataSource dataSource, final Collection<RuleConfiguration> configs, final Properties props) throws SQLException {
+        return createDataSource(DefaultSchema.LOGIC_NAME, Collections.singletonMap(DefaultSchema.LOGIC_NAME, dataSource), configs, props);
     }
     
     /**
      * Create ShardingSphere data source.
      *
+     * @param schemaName schema name
      * @param dataSource data source
-     * @param configurations rule configurations
+     * @param configs rule configurations
      * @param props properties for data source
-     * @param schemaName schema name for configurations
      * @return ShardingSphere data source
      * @throws SQLException SQL exception
      */
-    public static DataSource createDataSource(final DataSource dataSource, final Collection<RuleConfiguration> configurations, final Properties props,
-                                              final String schemaName) throws SQLException {
-        Map<String, DataSource> dataSourceMap = new HashMap<>(1, 1);
-        dataSourceMap.put(schemaName, dataSource);
-        return createDataSource(dataSourceMap, configurations, props, schemaName);
+    public static DataSource createDataSource(final String schemaName, final DataSource dataSource, final Collection<RuleConfiguration> configs, final Properties props) throws SQLException {
+        return createDataSource(schemaName, Collections.singletonMap(schemaName, dataSource), configs, props);
     }
 }
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/api/yaml/YamlShardingSphereDataSourceFactory.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/api/yaml/YamlShardingSphereDataSourceFactory.java
index 9b33573..201fb2c 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/api/yaml/YamlShardingSphereDataSourceFactory.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/api/yaml/YamlShardingSphereDataSourceFactory.java
@@ -51,9 +51,9 @@ public final class YamlShardingSphereDataSourceFactory {
      * @throws IOException IO exception
      */
     public static DataSource createDataSource(final File yamlFile) throws SQLException, IOException {
-        YamlRootRuleConfigurations configurations = YamlEngine.unmarshal(yamlFile, YamlRootRuleConfigurations.class);
-        return ShardingSphereDataSourceFactory.createDataSource(DATASOURCE_SWAPPER.swapToDataSources(configurations.getDataSources()),
-                SWAPPER_ENGINE.swapToRuleConfigurations(configurations.getRules()), configurations.getProps(), configurations.getSchemaName());
+        YamlRootRuleConfigurations configs = YamlEngine.unmarshal(yamlFile, YamlRootRuleConfigurations.class);
+        return ShardingSphereDataSourceFactory.createDataSource(
+                configs.getSchemaName(), DATASOURCE_SWAPPER.swapToDataSources(configs.getDataSources()), SWAPPER_ENGINE.swapToRuleConfigurations(configs.getRules()), configs.getProps());
     }
     
     /**
@@ -65,9 +65,9 @@ public final class YamlShardingSphereDataSourceFactory {
      * @throws IOException IO exception
      */
     public static DataSource createDataSource(final byte[] yamlBytes) throws SQLException, IOException {
-        YamlRootRuleConfigurations configurations = YamlEngine.unmarshal(yamlBytes, YamlRootRuleConfigurations.class);
-        return ShardingSphereDataSourceFactory.createDataSource(DATASOURCE_SWAPPER.swapToDataSources(configurations.getDataSources()),
-                SWAPPER_ENGINE.swapToRuleConfigurations(configurations.getRules()), configurations.getProps(), configurations.getSchemaName());
+        YamlRootRuleConfigurations configs = YamlEngine.unmarshal(yamlBytes, YamlRootRuleConfigurations.class);
+        return ShardingSphereDataSourceFactory.createDataSource(
+                configs.getSchemaName(), DATASOURCE_SWAPPER.swapToDataSources(configs.getDataSources()), SWAPPER_ENGINE.swapToRuleConfigurations(configs.getRules()), configs.getProps());
     }
     
     /**
@@ -80,9 +80,8 @@ public final class YamlShardingSphereDataSourceFactory {
      * @throws IOException IO exception
      */
     public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final File yamlFile) throws SQLException, IOException {
-        YamlRootRuleConfigurations configurations = YamlEngine.unmarshal(yamlFile, YamlRootRuleConfigurations.class);
-        return ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, SWAPPER_ENGINE.swapToRuleConfigurations(configurations.getRules()),
-                configurations.getProps(), configurations.getSchemaName());
+        YamlRootRuleConfigurations configs = YamlEngine.unmarshal(yamlFile, YamlRootRuleConfigurations.class);
+        return ShardingSphereDataSourceFactory.createDataSource(configs.getSchemaName(), dataSourceMap, SWAPPER_ENGINE.swapToRuleConfigurations(configs.getRules()), configs.getProps());
     }
     
     /**
@@ -95,9 +94,9 @@ public final class YamlShardingSphereDataSourceFactory {
      * @throws IOException IO exception
      */
     public static DataSource createDataSource(final DataSource dataSource, final File yamlFile) throws SQLException, IOException {
-        YamlRootRuleConfigurations configurations = YamlEngine.unmarshal(yamlFile, YamlRootRuleConfigurations.class);
+        YamlRootRuleConfigurations configs = YamlEngine.unmarshal(yamlFile, YamlRootRuleConfigurations.class);
         Map<String, DataSource> dataSourceMap = new HashMap<>(1, 1);
-        dataSourceMap.put(configurations.getSchemaName(), dataSource);
+        dataSourceMap.put(configs.getSchemaName(), dataSource);
         return createDataSource(dataSourceMap, yamlFile);
     }
     
@@ -111,9 +110,8 @@ public final class YamlShardingSphereDataSourceFactory {
      * @throws IOException IO exception
      */
     public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final byte[] yamlBytes) throws SQLException, IOException {
-        YamlRootRuleConfigurations configurations = YamlEngine.unmarshal(yamlBytes, YamlRootRuleConfigurations.class);
-        return ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, SWAPPER_ENGINE.swapToRuleConfigurations(configurations.getRules()),
-                configurations.getProps(), configurations.getSchemaName());
+        YamlRootRuleConfigurations configs = YamlEngine.unmarshal(yamlBytes, YamlRootRuleConfigurations.class);
+        return ShardingSphereDataSourceFactory.createDataSource(configs.getSchemaName(), dataSourceMap, SWAPPER_ENGINE.swapToRuleConfigurations(configs.getRules()), configs.getProps());
     }
     
     /**
@@ -127,9 +125,9 @@ public final class YamlShardingSphereDataSourceFactory {
      */
     public static DataSource createDataSource(final DataSource dataSource, final byte[] yamlBytes) throws SQLException, IOException {
         //TODO Analytical optimization yml
-        YamlRootRuleConfigurations configurations = YamlEngine.unmarshal(yamlBytes, YamlRootRuleConfigurations.class);
+        YamlRootRuleConfigurations configs = YamlEngine.unmarshal(yamlBytes, YamlRootRuleConfigurations.class);
         Map<String, DataSource> dataSourceMap = new HashMap<>(1, 1);
-        dataSourceMap.put(configurations.getSchemaName(), dataSource);
+        dataSourceMap.put(configs.getSchemaName(), dataSource);
         return createDataSource(dataSourceMap, yamlBytes);
     }
 }
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
index 1ad7013..29acd45 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
@@ -50,12 +50,12 @@ import java.util.Properties;
 @Getter
 public final class ShardingSphereDataSource extends AbstractUnsupportedOperationDataSource implements AutoCloseable {
     
+    private final String schemaName;
+    
     private final MetaDataContexts metaDataContexts;
     
     private final TransactionContexts transactionContexts;
     
-    private final String schemaName;
-    
     public ShardingSphereDataSource(final Map<String, DataSource> dataSourceMap, final Collection<RuleConfiguration> ruleConfigs, final Properties props) throws SQLException {
         schemaName = DefaultSchema.LOGIC_NAME;
         DistMetaDataPersistRepository repository = DistMetaDataPersistRepositoryFactory.newInstance(findDistMetaDataPersistRuleConfiguration(ruleConfigs));
@@ -65,13 +65,13 @@ public final class ShardingSphereDataSource extends AbstractUnsupportedOperation
         transactionContexts = createTransactionContexts(metaDataContexts.getDefaultMetaData().getResource().getDatabaseType(), dataSourceMap, xaTransactionMangerType);
     }
     
-    public ShardingSphereDataSource(final Map<String, DataSource> dataSourceMap, final Collection<RuleConfiguration> ruleConfigs, final Properties props, final String schemaName) throws SQLException {
+    public ShardingSphereDataSource(final String schemaName, final Map<String, DataSource> dataSourceMap, final Collection<RuleConfiguration> ruleConfigs, final Properties props) throws SQLException {
         this.schemaName = getSchemaName(schemaName);
         DistMetaDataPersistRepository repository = DistMetaDataPersistRepositoryFactory.newInstance(findDistMetaDataPersistRuleConfiguration(ruleConfigs));
-        metaDataContexts = new MetaDataContextsBuilder(Collections.singletonMap(getSchemaName(schemaName), dataSourceMap),
-                Collections.singletonMap(getSchemaName(schemaName), ruleConfigs), props).build(new DistMetaDataPersistService(repository));
+        metaDataContexts = new MetaDataContextsBuilder(Collections.singletonMap(this.schemaName, dataSourceMap),
+                Collections.singletonMap(this.schemaName, ruleConfigs), props).build(new DistMetaDataPersistService(repository));
         String xaTransactionMangerType = metaDataContexts.getProps().getValue(ConfigurationPropertyKey.XA_TRANSACTION_MANAGER_TYPE);
-        transactionContexts = createTransactionContexts(metaDataContexts.getMetaData(getSchemaName(schemaName)).getResource().getDatabaseType(), dataSourceMap, xaTransactionMangerType);
+        transactionContexts = createTransactionContexts(metaDataContexts.getMetaData(this.schemaName).getResource().getDatabaseType(), dataSourceMap, xaTransactionMangerType);
     }
     
     private String getSchemaName(final String schemaName) {
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/api/ShardingSphereDataSourceFactoryTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/api/ShardingSphereDataSourceFactoryTest.java
index 2daf457..2c44dbb 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/api/ShardingSphereDataSourceFactoryTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/api/ShardingSphereDataSourceFactoryTest.java
@@ -40,7 +40,7 @@ public final class ShardingSphereDataSourceFactoryTest {
     public void assertCreateDataSourceWithMultipleActualDataSources() throws SQLException {
         Properties props = new Properties();
         ShardingSphereDataSource dataSource = (ShardingSphereDataSource) ShardingSphereDataSourceFactory.createDataSource(
-                getDataSourceMap(), Collections.singleton(createShardingRuleConfiguration()), props, DefaultSchema.LOGIC_NAME);
+                DefaultSchema.LOGIC_NAME, getDataSourceMap(), Collections.singleton(createShardingRuleConfiguration()), props);
         assertThat(dataSource.getMetaDataContexts().getProps().getProps(), is(props));
     }
     
@@ -56,7 +56,7 @@ public final class ShardingSphereDataSourceFactoryTest {
     public void assertCreateDataSourceWithSingleActualDataSource() throws SQLException {
         Properties props = new Properties();
         ShardingSphereDataSource dataSource = (ShardingSphereDataSource) ShardingSphereDataSourceFactory.createDataSource(
-                new MockedDataSource(), Collections.singleton(createShardingRuleConfiguration()), props, DefaultSchema.LOGIC_NAME);
+                DefaultSchema.LOGIC_NAME, new MockedDataSource(), Collections.singleton(createShardingRuleConfiguration()), props);
         assertThat(dataSource.getMetaDataContexts().getProps().getProps(), is(props));
     }
     
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/WrapperAdapterTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/WrapperAdapterTest.java
index 8a6f8dc..0e460e0 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/WrapperAdapterTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/WrapperAdapterTest.java
@@ -43,7 +43,7 @@ public final class WrapperAdapterTest {
     
     @Before
     public void setUp() throws SQLException {
-        shardingSphereDataSource = new ShardingSphereDataSource(Collections.emptyMap(), Collections.emptyList(), new Properties(), DefaultSchema.LOGIC_NAME);
+        shardingSphereDataSource = new ShardingSphereDataSource(DefaultSchema.LOGIC_NAME, Collections.emptyMap(), Collections.emptyList(), new Properties());
     }
     
     @Test
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
index ae3ce7e..4be1dbd 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
@@ -180,7 +180,7 @@ public final class ShardingSphereDataSourceTest {
     }
     
     private ShardingSphereDataSource createShardingSphereDataSource(final Map<String, DataSource> dataSourceMap) throws SQLException {
-        return new ShardingSphereDataSource(dataSourceMap, Collections.singletonList(createShardingRuleConfig(dataSourceMap)), new Properties(), DefaultSchema.LOGIC_NAME);
+        return new ShardingSphereDataSource(DefaultSchema.LOGIC_NAME, dataSourceMap, Collections.singletonList(createShardingRuleConfig(dataSourceMap)), new Properties());
     }
     
     private ShardingRuleConfiguration createShardingRuleConfig(final Map<String, DataSource> dataSourceMap) {
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationDataSourceTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationDataSourceTest.java
index f8dadc8..02a02f2 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationDataSourceTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationDataSourceTest.java
@@ -33,7 +33,7 @@ public final class UnsupportedOperationDataSourceTest {
     
     @Before
     public void setUp() throws SQLException {
-        shardingSphereDataSource = new ShardingSphereDataSource(Collections.emptyMap(), Collections.emptyList(), new Properties(), DefaultSchema.LOGIC_NAME);
+        shardingSphereDataSource = new ShardingSphereDataSource(DefaultSchema.LOGIC_NAME, Collections.emptyMap(), Collections.emptyList(), new Properties());
     }
     
     @Test(expected = SQLFeatureNotSupportedException.class)
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/api/GovernanceShardingSphereDataSourceFactory.java b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/api/GovernanceShardingSphereDataSourceFactory.java
index 91c02cb..cd5a580 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/api/GovernanceShardingSphereDataSourceFactory.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/api/GovernanceShardingSphereDataSourceFactory.java
@@ -58,20 +58,20 @@ public final class GovernanceShardingSphereDataSourceFactory {
     /**
      * Create ShardingSphere data source.
      *
+     * @param schemaName schema name
      * @param dataSourceMap data source map
      * @param ruleConfigurations rule configurations
      * @param governanceConfig governance configuration
      * @param props properties for data source
-     * @param schemaName schema name configuration
      * @return ShardingSphere data source
      * @throws SQLException SQL exception
      */
-    public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final Collection<RuleConfiguration> ruleConfigurations,
-                                              final Properties props, final GovernanceConfiguration governanceConfig, final String schemaName) throws SQLException {
+    public static DataSource createDataSource(final String schemaName, final Map<String, DataSource> dataSourceMap, final Collection<RuleConfiguration> ruleConfigurations,
+                                              final Properties props, final GovernanceConfiguration governanceConfig) throws SQLException {
         if (null == ruleConfigurations || ruleConfigurations.isEmpty()) {
-            return createDataSource(governanceConfig, schemaName);
+            return createDataSource(schemaName, governanceConfig);
         }
-        return new GovernanceShardingSphereDataSource(dataSourceMap, ruleConfigurations, props, governanceConfig, schemaName);
+        return new GovernanceShardingSphereDataSource(schemaName, dataSourceMap, ruleConfigurations, props, governanceConfig);
     }
     
     /**
@@ -88,26 +88,25 @@ public final class GovernanceShardingSphereDataSourceFactory {
                                               final Properties props, final GovernanceConfiguration governanceConfig) throws SQLException {
         Map<String, DataSource> dataSourceMap = new HashMap<>(1, 1);
         dataSourceMap.put(DefaultSchema.LOGIC_NAME, dataSource);
-        return createDataSource(dataSourceMap, ruleConfigurations, props, governanceConfig, DefaultSchema.LOGIC_NAME);
+        return createDataSource(DefaultSchema.LOGIC_NAME, dataSourceMap, ruleConfigurations, props, governanceConfig);
     }
     
     /**
      * Create ShardingSphere data source.
      *
+     * @param schemaName schema name configuration
      * @param dataSource data source
      * @param ruleConfigurations rule configurations
      * @param governanceConfig governance configuration
      * @param props properties for data source
-     * @param schemaName schema name configuration
      * @return ShardingSphere data source
      * @throws SQLException SQL exception
      */
-    public static DataSource createDataSource(final DataSource dataSource, final Collection<RuleConfiguration> ruleConfigurations,
-                                              final Properties props, final GovernanceConfiguration governanceConfig,
-                                              final String schemaName) throws SQLException {
+    public static DataSource createDataSource(final String schemaName, final DataSource dataSource, final Collection<RuleConfiguration> ruleConfigurations,
+                                              final Properties props, final GovernanceConfiguration governanceConfig) throws SQLException {
         Map<String, DataSource> dataSourceMap = new HashMap<>(1, 1);
         dataSourceMap.put(schemaName, dataSource);
-        return createDataSource(dataSourceMap, ruleConfigurations, props, governanceConfig, schemaName);
+        return createDataSource(schemaName, dataSourceMap, ruleConfigurations, props, governanceConfig);
     }
     
     /**
@@ -124,12 +123,12 @@ public final class GovernanceShardingSphereDataSourceFactory {
     /**
      * Create ShardingSphere data source.
      *
+     * @param schemaName schema name
      * @param governanceConfig governance configuration
-     * @param schemaName schema name configuration
      * @return ShardingSphere data source
      * @throws SQLException SQL exception
      */
-    public static DataSource createDataSource(final GovernanceConfiguration governanceConfig, final String schemaName) throws SQLException {
-        return new GovernanceShardingSphereDataSource(governanceConfig, schemaName);
+    public static DataSource createDataSource(final String schemaName, final GovernanceConfiguration governanceConfig) throws SQLException {
+        return new GovernanceShardingSphereDataSource(schemaName, governanceConfig);
     }
 }
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/api/yaml/YamlGovernanceShardingSphereDataSourceFactory.java b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/api/yaml/YamlGovernanceShardingSphereDataSourceFactory.java
index b2c592f..2716bd1 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/api/yaml/YamlGovernanceShardingSphereDataSourceFactory.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/api/yaml/YamlGovernanceShardingSphereDataSourceFactory.java
@@ -51,9 +51,8 @@ public final class YamlGovernanceShardingSphereDataSourceFactory {
      * @throws IOException IO exception
      */
     public static DataSource createDataSource(final File yamlFile) throws SQLException, IOException {
-        YamlGovernanceRootRuleConfigurations configurations = unmarshal(yamlFile);
-        return createDataSource(new YamlDataSourceConfigurationSwapper().swapToDataSources(configurations.getDataSources()),
-                configurations, configurations.getProps(), configurations.getGovernance(), configurations.getSchemaName());
+        YamlGovernanceRootRuleConfigurations configs = unmarshal(yamlFile);
+        return createDataSource(configs.getSchemaName(), new YamlDataSourceConfigurationSwapper().swapToDataSources(configs.getDataSources()), configs, configs.getProps(), configs.getGovernance());
     }
     
     /**
@@ -66,8 +65,8 @@ public final class YamlGovernanceShardingSphereDataSourceFactory {
      * @throws IOException IO exception
      */
     public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final File yamlFile) throws SQLException, IOException {
-        YamlGovernanceRootRuleConfigurations configurations = unmarshal(yamlFile);
-        return createDataSource(dataSourceMap, configurations, configurations.getProps(), configurations.getGovernance(), configurations.getSchemaName());
+        YamlGovernanceRootRuleConfigurations configs = unmarshal(yamlFile);
+        return createDataSource(configs.getSchemaName(), dataSourceMap, configs, configs.getProps(), configs.getGovernance());
     }
     
     /**
@@ -79,9 +78,8 @@ public final class YamlGovernanceShardingSphereDataSourceFactory {
      * @throws IOException IO exception
      */
     public static DataSource createDataSource(final byte[] yamlBytes) throws SQLException, IOException {
-        YamlGovernanceRootRuleConfigurations configurations = unmarshal(yamlBytes);
-        return createDataSource(new YamlDataSourceConfigurationSwapper().swapToDataSources(configurations.getDataSources()),
-                configurations, configurations.getProps(), configurations.getGovernance(), configurations.getSchemaName());
+        YamlGovernanceRootRuleConfigurations configs = unmarshal(yamlBytes);
+        return createDataSource(configs.getSchemaName(), new YamlDataSourceConfigurationSwapper().swapToDataSources(configs.getDataSources()), configs, configs.getProps(), configs.getGovernance());
     }
     
     /**
@@ -94,30 +92,26 @@ public final class YamlGovernanceShardingSphereDataSourceFactory {
      * @throws IOException IO exception
      */
     public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final byte[] yamlBytes) throws SQLException, IOException {
-        YamlGovernanceRootRuleConfigurations configurations = unmarshal(yamlBytes);
-        return createDataSource(dataSourceMap, configurations, configurations.getProps(), configurations.getGovernance(), configurations.getSchemaName());
+        YamlGovernanceRootRuleConfigurations configs = unmarshal(yamlBytes);
+        return createDataSource(configs.getSchemaName(), dataSourceMap, configs, configs.getProps(), configs.getGovernance());
     }
     
-    private static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final YamlGovernanceRootRuleConfigurations configurations,
-                                               final Properties props, final YamlGovernanceConfiguration governance,
-                                               final String schemaName) throws SQLException {
-        if (configurations.getRules().isEmpty() || dataSourceMap.isEmpty()) {
-            return createDataSourceWithoutRules(governance, schemaName);
+    private static DataSource createDataSource(final String schemaName, final Map<String, DataSource> dataSourceMap, final YamlGovernanceRootRuleConfigurations configs,
+                                               final Properties props, final YamlGovernanceConfiguration governance) throws SQLException {
+        if (configs.getRules().isEmpty() || dataSourceMap.isEmpty()) {
+            return createDataSourceWithoutRules(schemaName, governance);
         } else {
-            return createDataSourceWithRules(dataSourceMap, new YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(configurations.getRules()),
-                    props, governance, schemaName);
+            return createDataSourceWithRules(schemaName, dataSourceMap, new YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(configs.getRules()), props, governance);
         }
     }
     
-    private static DataSource createDataSourceWithoutRules(final YamlGovernanceConfiguration governance, final String schemaName) throws SQLException {
-        return new GovernanceShardingSphereDataSource(YamlGovernanceConfigurationSwapperUtil.marshal(governance), schemaName);
+    private static DataSource createDataSourceWithoutRules(final String schemaName, final YamlGovernanceConfiguration governance) throws SQLException {
+        return new GovernanceShardingSphereDataSource(schemaName, YamlGovernanceConfigurationSwapperUtil.marshal(governance));
     }
     
-    private static DataSource createDataSourceWithRules(final Map<String, DataSource> dataSourceMap, final Collection<RuleConfiguration> ruleConfigurations,
-                                                        final Properties props, final YamlGovernanceConfiguration governance,
-                                                        final String schemaName) throws SQLException {
-        return new GovernanceShardingSphereDataSource(dataSourceMap, ruleConfigurations, props, 
-                YamlGovernanceConfigurationSwapperUtil.marshal(governance), schemaName);
+    private static DataSource createDataSourceWithRules(final String schemaName, final Map<String, DataSource> dataSourceMap, 
+                                                        final Collection<RuleConfiguration> ruleConfigs, final Properties props, final YamlGovernanceConfiguration governance) throws SQLException {
+        return new GovernanceShardingSphereDataSource(schemaName, dataSourceMap, ruleConfigs, props, YamlGovernanceConfigurationSwapperUtil.marshal(governance));
     }
     
     private static YamlGovernanceRootRuleConfigurations unmarshal(final File yamlFile) throws IOException {
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/datasource/GovernanceShardingSphereDataSource.java b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/datasource/GovernanceShardingSphereDataSource.java
index d477551..8135f57 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/datasource/GovernanceShardingSphereDataSource.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/datasource/GovernanceShardingSphereDataSource.java
@@ -57,6 +57,8 @@ import java.util.stream.Collectors;
  */
 public final class GovernanceShardingSphereDataSource extends AbstractUnsupportedOperationDataSource implements AutoCloseable {
     
+    private final String schemaName;
+    
     private final GovernanceRule governanceRule;
     
     @Getter
@@ -65,8 +67,6 @@ public final class GovernanceShardingSphereDataSource extends AbstractUnsupporte
     @Getter
     private final TransactionContexts transactionContexts;
     
-    private final String schemaName;
-    
     public GovernanceShardingSphereDataSource(final GovernanceConfiguration governanceConfig) throws SQLException {
         schemaName = DefaultSchema.LOGIC_NAME;
         // TODO new GovernanceRule from SPI
@@ -79,7 +79,7 @@ public final class GovernanceShardingSphereDataSource extends AbstractUnsupporte
         new TransactionContextsSubscriber(transactionContexts, xaTransactionMangerType);
     }
     
-    public GovernanceShardingSphereDataSource(final GovernanceConfiguration governanceConfig, final String schemaName) throws SQLException {
+    public GovernanceShardingSphereDataSource(final String schemaName, final GovernanceConfiguration governanceConfig) throws SQLException {
         this.schemaName = getSchemaName(schemaName);
         // TODO new GovernanceRule from SPI
         governanceRule = new GovernanceRule(governanceConfig);
@@ -105,8 +105,8 @@ public final class GovernanceShardingSphereDataSource extends AbstractUnsupporte
         new TransactionContextsSubscriber(transactionContexts, xaTransactionMangerType);
     }
     
-    public GovernanceShardingSphereDataSource(final Map<String, DataSource> dataSourceMap, final Collection<RuleConfiguration> ruleConfigs,
-                                              final Properties props, final GovernanceConfiguration governanceConfig, final String schemaName) throws SQLException {
+    public GovernanceShardingSphereDataSource(final String schemaName, final Map<String, DataSource> dataSourceMap, final Collection<RuleConfiguration> ruleConfigs,
+                                              final Properties props, final GovernanceConfiguration governanceConfig) throws SQLException {
         this.schemaName = getSchemaName(schemaName);
         // TODO new GovernanceRule from SPI
         governanceRule = new GovernanceRule(governanceConfig);
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/main/java/org/apache/shardingsphere/spring/boot/ShardingSphereAutoConfiguration.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/main/java/org/apache/shardingsphere/spring/boot/ShardingSphereAutoConfiguration.java
index 8567083..48de376 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/main/java/org/apache/shardingsphere/spring/boot/ShardingSphereAutoConfiguration.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/main/java/org/apache/shardingsphere/spring/boot/ShardingSphereAutoConfiguration.java
@@ -56,12 +56,12 @@ import java.util.Optional;
 @RequiredArgsConstructor
 public class ShardingSphereAutoConfiguration implements EnvironmentAware {
     
+    private String schemaName;
+    
     private final SpringBootPropertiesConfiguration props;
     
     private final Map<String, DataSource> dataSourceMap = new LinkedHashMap<>();
     
-    private String schemaName;
-    
     /**
      * Get ShardingSphere data source bean.
      *
@@ -73,7 +73,7 @@ public class ShardingSphereAutoConfiguration implements EnvironmentAware {
     @Autowired(required = false)
     public DataSource shardingSphereDataSource(final ObjectProvider<List<RuleConfiguration>> rules) throws SQLException {
         Collection<RuleConfiguration> ruleConfigurations = Optional.ofNullable(rules.getIfAvailable()).orElse(Collections.emptyList());
-        return ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, ruleConfigurations, props.getProps(), schemaName);
+        return ShardingSphereDataSourceFactory.createDataSource(schemaName, dataSourceMap, ruleConfigurations, props.getProps());
     }
     
     /**
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/parser/DataSourceBeanDefinitionParser.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/parser/DataSourceBeanDefinitionParser.java
index bd9ce8f..493ee3e 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/parser/DataSourceBeanDefinitionParser.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/parser/DataSourceBeanDefinitionParser.java
@@ -43,14 +43,18 @@ public final class DataSourceBeanDefinitionParser extends AbstractBeanDefinition
     @Override
     protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
         BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(ShardingSphereDataSource.class);
+        factory.addConstructorArgValue(parseSchemaName(element));
         factory.addConstructorArgValue(parseDataSources(element));
         factory.addConstructorArgValue(parseRuleConfigurations(element));
         factory.addConstructorArgValue(parseProperties(element, parserContext));
-        factory.addConstructorArgValue(parseSchemaName(element));
         factory.setDestroyMethodName("close");
         return factory.getBeanDefinition();
     }
     
+    private String parseSchemaName(final Element element) {
+        return element.getAttribute(DataSourceBeanDefinitionTag.SCHEMA_NAME_TAG);
+    }
+    
     private Map<String, RuntimeBeanReference> parseDataSources(final Element element) {
         List<String> dataSources = Splitter.on(",").trimResults().splitToList(element.getAttribute(DataSourceBeanDefinitionTag.DATA_SOURCE_NAMES_TAG));
         Map<String, RuntimeBeanReference> result = new ManagedMap<>(dataSources.size());
@@ -73,8 +77,4 @@ public final class DataSourceBeanDefinitionParser extends AbstractBeanDefinition
         Element propsElement = DomUtils.getChildElementByTagName(element, DataSourceBeanDefinitionTag.PROPS_TAG);
         return null == propsElement ? new Properties() : parserContext.getDelegate().parsePropsElement(propsElement);
     }
-    
-    private String parseSchemaName(final Element element) {
-        return element.getAttribute(DataSourceBeanDefinitionTag.SCHEMA_NAME_TAG);
-    }
 }
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/main/resources/META-INF/namespace/datasource.xsd b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/main/resources/META-INF/namespace/datasource.xsd
index 22bab05..a33807a 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/main/resources/META-INF/namespace/datasource.xsd
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/main/resources/META-INF/namespace/datasource.xsd
@@ -29,9 +29,9 @@
                 <xsd:element ref="beans:props" minOccurs="0" />
             </xsd:all>
             <xsd:attribute name="id" type="xsd:string" use="required" />
+            <xsd:attribute name="schema-name" type="xsd:string" />
             <xsd:attribute name="data-source-names" type="xsd:string" use="required" />
             <xsd:attribute name="rule-refs" type="xsd:string" use="required" />
-            <xsd:attribute name="schema-name" type="xsd:string" />
         </xsd:complexType>
     </xsd:element>
     
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/resources/META-INF/spring/application-context.xml b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/resources/META-INF/spring/application-context.xml
index d1ded5c..1083d36 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/resources/META-INF/spring/application-context.xml
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/resources/META-INF/spring/application-context.xml
@@ -82,7 +82,7 @@
         <readwrite-splitting:data-source-rule id="ds_1" write-data-source-name="ds_1_write" read-data-source-names="ds_1_read_0,ds_1_read_1" />
     </readwrite-splitting:rule>
     
-    <shardingsphere:data-source id="dataSource" data-source-names="ds_0_write,ds_0_read_0,ds_0_read_1,ds_1_write,ds_1_read_0,ds_1_read_1" rule-refs="shardingRule, readWriteSplittingRule, encryptRule" schema-name="logic_db">
+    <shardingsphere:data-source id="dataSource" schema-name="logic_db" data-source-names="ds_0_write,ds_0_read_0,ds_0_read_1,ds_1_write,ds_1_read_0,ds_1_read_1" rule-refs="shardingRule, readWriteSplittingRule, encryptRule">
         <props>
             <prop key="sql-show">false</prop>
             <prop key="executor-size">${executor-size}</prop>
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-boot-starter/src/main/java/org/apache/shardingsphere/spring/boot/governance/ShardingSphereGovernanceAutoConfiguration.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-boot-starter/src/main/java/org/apache/shardingsphere/spring/boot/governance/ShardingSphereGovernanceAutoConfi [...]
index 0d715ee..d83d62d 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-boot-starter/src/main/java/org/apache/shardingsphere/spring/boot/governance/ShardingSphereGovernanceAutoConfiguration.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-boot-starter/src/main/java/org/apache/shardingsphere/spring/boot/governance/ShardingSphereGovernanceAutoConfiguration.java
@@ -20,9 +20,9 @@ package org.apache.shardingsphere.spring.boot.governance;
 import com.google.common.base.Preconditions;
 import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.driver.governance.internal.datasource.GovernanceShardingSphereDataSource;
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.governance.core.yaml.swapper.RegistryCenterConfigurationYamlSwapper;
 import org.apache.shardingsphere.governance.repository.api.config.GovernanceConfiguration;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.spring.boot.datasource.DataSourceMapSetter;
 import org.apache.shardingsphere.spring.boot.governance.common.GovernanceSpringBootRootConfiguration;
 import org.apache.shardingsphere.spring.boot.governance.rule.LocalRulesCondition;
@@ -61,14 +61,14 @@ import java.util.Optional;
 @AutoConfigureBefore(DataSourceAutoConfiguration.class)
 public class ShardingSphereGovernanceAutoConfiguration implements EnvironmentAware {
     
+    private String schemaName;
+    
     private final Map<String, DataSource> dataSourceMap = new LinkedHashMap<>();
     
     private final GovernanceSpringBootRootConfiguration root;
     
     private final RegistryCenterConfigurationYamlSwapper swapper = new RegistryCenterConfigurationYamlSwapper();
     
-    private String schemaName;
-    
     /**
      * Get governance configuration.
      *
@@ -111,15 +111,15 @@ public class ShardingSphereGovernanceAutoConfiguration implements EnvironmentAwa
     
     @Override
     public final void setEnvironment(final Environment environment) {
-        dataSourceMap.putAll(DataSourceMapSetter.getDataSourceMap(environment));
         schemaName = SchemaNameSetter.getSchemaName(environment);
+        dataSourceMap.putAll(DataSourceMapSetter.getDataSourceMap(environment));
     }
     
     private DataSource createDataSourceWithRules(final List<RuleConfiguration> ruleConfigs, final GovernanceConfiguration governanceConfig) throws SQLException {
-        return new GovernanceShardingSphereDataSource(dataSourceMap, ruleConfigs, root.getProps(), governanceConfig, schemaName);
+        return new GovernanceShardingSphereDataSource(schemaName, dataSourceMap, ruleConfigs, root.getProps(), governanceConfig);
     }
     
     private DataSource createDataSourceWithoutRules(final GovernanceConfiguration governanceConfig) throws SQLException {
-        return new GovernanceShardingSphereDataSource(governanceConfig, schemaName);
+        return new GovernanceShardingSphereDataSource(schemaName, governanceConfig);
     }
 }
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/governance/parser/DataSourceBeanDefinitionParser.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/governance/parser/DataSourceBeanDefinitionPa [...]
index 5ca1fbe..4860e34 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/governance/parser/DataSourceBeanDefinitionParser.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/main/java/org/apache/shardingsphere/spring/namespace/governance/parser/DataSourceBeanDefinitionParser.java
@@ -51,6 +51,7 @@ public final class DataSourceBeanDefinitionParser extends AbstractBeanDefinition
     }
     
     private void configureFactory(final Element element, final ParserContext parserContext, final BeanDefinitionBuilder factory) {
+        factory.addConstructorArgValue(parseSchemaName(element));
         String dataSourceNames = element.getAttribute(DataSourceBeanDefinitionTag.DATA_SOURCE_NAMES_TAG);
         if (!Strings.isNullOrEmpty(dataSourceNames)) {
             factory.addConstructorArgValue(parseDataSources(element));
@@ -58,10 +59,13 @@ public final class DataSourceBeanDefinitionParser extends AbstractBeanDefinition
             factory.addConstructorArgValue(parseProperties(element, parserContext));
         }
         factory.addConstructorArgValue(getGovernanceConfiguration(element));
-        factory.addConstructorArgValue(parseSchemaName(element));
         factory.setDestroyMethodName("close");
     }
     
+    private String parseSchemaName(final Element element) {
+        return element.getAttribute(DataSourceBeanDefinitionTag.SCHEMA_NAME_TAG);
+    }
+    
     private Map<String, RuntimeBeanReference> parseDataSources(final Element element) {
         List<String> dataSources = Splitter.on(",").trimResults().splitToList(element.getAttribute(DataSourceBeanDefinitionTag.DATA_SOURCE_NAMES_TAG));
         Map<String, RuntimeBeanReference> result = new ManagedMap<>(dataSources.size());
@@ -91,8 +95,4 @@ public final class DataSourceBeanDefinitionParser extends AbstractBeanDefinition
         factory.addConstructorArgValue(element.getAttribute(DataSourceBeanDefinitionTag.OVERWRITE_ATTRIBUTE));
         return factory.getBeanDefinition();
     }
-    
-    private String parseSchemaName(final Element element) {
-        return element.getAttribute(DataSourceBeanDefinitionTag.SCHEMA_NAME_TAG);
-    }
 }
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/ShardingSphereJDBCDataSourceConfiguration.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/ShardingSphereJDBCDataSourceConfiguration.java
index c0f31ca..a78e10c 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/ShardingSphereJDBCDataSourceConfiguration.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/config/datasource/ShardingSphereJDBCDataSourceConfiguration.java
@@ -72,8 +72,7 @@ public final class ShardingSphereJDBCDataSourceConfiguration implements ScalingD
     
     @Override
     public DataSource toDataSource() throws SQLException {
-        return ShardingSphereDataSourceFactory.createDataSource(new YamlDataSourceConfigurationSwapper().swapToDataSources(
-                rootRuleConfigs.getDataSources()), Collections.singletonList(ShardingRuleConfigurationSwapper.findAndConvertShardingRuleConfiguration(rootRuleConfigs.getRules())),
-                null, rootRuleConfigs.getSchemaName());
+        return ShardingSphereDataSourceFactory.createDataSource(rootRuleConfigs.getSchemaName(), new YamlDataSourceConfigurationSwapper().swapToDataSources(
+                rootRuleConfigs.getDataSources()), Collections.singletonList(ShardingRuleConfigurationSwapper.findAndConvertShardingRuleConfiguration(rootRuleConfigs.getRules())), null);
     }
 }