You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2020/06/13 12:00:00 UTC

[shardingsphere] branch master updated: Add shardingsphere-jdbc-spring-namespace-infra module (#6026)

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

panjuan 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 8c79331  Add shardingsphere-jdbc-spring-namespace-infra module (#6026)
8c79331 is described below

commit 8c79331f53a6f380450e91bc91acf01bd0fe5b08
Author: Liang Zhang <te...@163.com>
AuthorDate: Sat Jun 13 19:59:43 2020 +0800

    Add shardingsphere-jdbc-spring-namespace-infra module (#6026)
    
    * Add shardingsphere-jdbc-spring-namespace-infra module
    
    * Add ShardingSphereAlgorithmBeanDefinitionParser
    
    * Refactor ShardingSphereAlgorithmBeanDefinitionParser
    
    * Refactor tag
    
    * remove useless codes
    
    * Add ShardingSphereAlgorithmBeanRegistry
    
    * refactor AlgorithmProvidedEncryptRuleConfiguration
    
    * refactor AlgorithmProvidedShardingRuleConfiguration
    
    * for code style
---
 .../AlgorithmProvidedEncryptRuleConfiguration.java |   4 +-
 .../pom.xml                                        |   5 +
 .../factorybean/EncryptAlgorithmFactoryBean.java   |  26 +-----
 .../handler/EncryptRuleNamespaceHandler.java       |   7 +-
 .../EncryptAlgorithmBeanDefinitionParser.java      |  48 ----------
 .../parser/EncryptRuleBeanDefinitionParser.java    |  32 +------
 .../tag/EncryptAlgorithmBeanDefinitionTag.java     |   4 -
 .../pom.xml                                        |   5 +
 ...MasterSlaveLoadBalanceAlgorithmFactoryBean.java |  26 +-----
 .../handler/MasterSlaveNamespaceHandler.java       |   5 +-
 ...veLoadBalanceAlgorithmBeanDefinitionParser.java |  48 ----------
 .../MasterSlaveRuleBeanDefinitionParser.java       |  25 +----
 .../tag/LoadBalanceAlgorithmBeanDefinitionTag.java |   4 -
 .../api/config/ShardingRuleConfiguration.java      |   4 +-
 .../sharding/spi/ShardingAlgorithm.java            |   4 +-
 ...AlgorithmProvidedShardingRuleConfiguration.java |  21 ++---
 .../pom.xml                                        |   5 +
 .../KeyGenerateAlgorithmFactoryBean.java           |  30 +-----
 .../factorybean/ShardingAlgorithmFactoryBean.java  |  32 +------
 .../handler/ShardingNamespaceHandler.java          |   9 +-
 .../KeyGenerateAlgorithmBeanDefinitionParser.java  |  48 ----------
 .../rule/ShardingRuleBeanDefinitionParser.java     | 101 ++++++++-------------
 .../KeyGenerateAlgorithmBeanDefinitionTag.java     |   4 -
 .../ShardingAlgorithmBeanDefinitionTag.java        |   4 -
 .../ShardingSphereAlgorithmPostProcessor.java      |   2 -
 .../shardingsphere-jdbc-spring-infra/pom.xml       |   1 +
 .../pom.xml                                        |   6 +-
 .../ShardingSphereAlgorithmFactoryBean.java        |  26 ++----
 ...hardingSphereAlgorithmBeanDefinitionParser.java |  24 +++--
 .../ShardingSphereAlgorithmBeanRegistry.java       |  53 +++++++++++
 .../ShardingSphereAlgorithmBeanDefinitionTag.java  |   8 +-
 31 files changed, 189 insertions(+), 432 deletions(-)

diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/algorithm/config/AlgorithmProvidedEncryptRuleConfiguration.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/algorithm/config/AlgorithmProvidedEncryptRuleConfiguration.java
index e02a2f7..b8fea6c 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/algorithm/config/AlgorithmProvidedEncryptRuleConfiguration.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/algorithm/config/AlgorithmProvidedEncryptRuleConfiguration.java
@@ -33,7 +33,7 @@ import java.util.Map;
 @Getter
 public final class AlgorithmProvidedEncryptRuleConfiguration implements RuleConfiguration {
     
-    private final Map<String, EncryptAlgorithm> encryptors;
-    
     private final Collection<EncryptTableRuleConfiguration> tables;
+    
+    private final Map<String, EncryptAlgorithm> encryptors;
 }
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/pom.xml b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/pom.xml
index e34301f..26b7846 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/pom.xml
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/pom.xml
@@ -34,6 +34,11 @@
             <artifactId>shardingsphere-encrypt-common</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-jdbc-spring-namespace-infra</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         
         <dependency>
             <groupId>org.springframework</groupId>
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/factorybean/EncryptAlgorithmFactoryBean.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/factorybean/EncryptAlgorithmFactoryBean.java
index 3707c12..ec57169 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/factorybean/EncryptAlgorithmFactoryBean.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/factorybean/EncryptAlgorithmFactoryBean.java
@@ -17,40 +17,22 @@
 
 package org.apache.shardingsphere.encrypt.spring.namespace.factorybean;
 
-import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
 import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.spi.type.TypedSPIRegistry;
-import org.springframework.beans.factory.FactoryBean;
+import org.apache.shardingsphere.spring.namespace.factorybean.ShardingSphereAlgorithmFactoryBean;
 
 import java.util.Properties;
 
 /**
  * Encrypt algorithm factory bean.
  */
-@RequiredArgsConstructor
-public final class EncryptAlgorithmFactoryBean implements FactoryBean<EncryptAlgorithm> {
+public final class EncryptAlgorithmFactoryBean extends ShardingSphereAlgorithmFactoryBean<EncryptAlgorithm> {
     
     static {
         ShardingSphereServiceLoader.register(EncryptAlgorithm.class);
     }
     
-    private final String type;
-    
-    private final Properties props;
-    
-    @Override
-    public EncryptAlgorithm getObject() {
-        return TypedSPIRegistry.getRegisteredService(EncryptAlgorithm.class, type, props);
-    }
-    
-    @Override
-    public Class<?> getObjectType() {
-        return EncryptAlgorithm.class;
-    }
-    
-    @Override
-    public boolean isSingleton() {
-        return true;
+    public EncryptAlgorithmFactoryBean(final String type, final Properties props) {
+        super(type, props, EncryptAlgorithm.class);
     }
 }
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/handler/EncryptRuleNamespaceHandler.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/handler/EncryptRuleNamespaceHandler.java
index 1a549da..2bdbdd8 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/handler/EncryptRuleNamespaceHandler.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/handler/EncryptRuleNamespaceHandler.java
@@ -17,10 +17,11 @@
 
 package org.apache.shardingsphere.encrypt.spring.namespace.handler;
 
+import org.apache.shardingsphere.encrypt.spring.namespace.factorybean.EncryptAlgorithmFactoryBean;
 import org.apache.shardingsphere.encrypt.spring.namespace.parser.EncryptRuleBeanDefinitionParser;
-import org.apache.shardingsphere.encrypt.spring.namespace.parser.EncryptAlgorithmBeanDefinitionParser;
-import org.apache.shardingsphere.encrypt.spring.namespace.tag.EncryptRuleBeanDefinitionTag;
 import org.apache.shardingsphere.encrypt.spring.namespace.tag.EncryptAlgorithmBeanDefinitionTag;
+import org.apache.shardingsphere.encrypt.spring.namespace.tag.EncryptRuleBeanDefinitionTag;
+import org.apache.shardingsphere.spring.namespace.parser.ShardingSphereAlgorithmBeanDefinitionParser;
 import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
 
 /**
@@ -31,6 +32,6 @@ public final class EncryptRuleNamespaceHandler extends NamespaceHandlerSupport {
     @Override
     public void init() {
         registerBeanDefinitionParser(EncryptRuleBeanDefinitionTag.ROOT_TAG, new EncryptRuleBeanDefinitionParser());
-        registerBeanDefinitionParser(EncryptAlgorithmBeanDefinitionTag.ROOT_TAG, new EncryptAlgorithmBeanDefinitionParser());
+        registerBeanDefinitionParser(EncryptAlgorithmBeanDefinitionTag.ROOT_TAG, new ShardingSphereAlgorithmBeanDefinitionParser(EncryptAlgorithmFactoryBean.class));
     }
 }
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/parser/EncryptAlgorithmBeanDefinitionParser.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/parser/EncryptAlgorithmBeanDefinitionParser.java
deleted file mode 100644
index 9c2bb01..0000000
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/parser/EncryptAlgorithmBeanDefinitionParser.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.encrypt.spring.namespace.parser;
-
-import org.apache.shardingsphere.encrypt.spring.namespace.factorybean.EncryptAlgorithmFactoryBean;
-import org.apache.shardingsphere.encrypt.spring.namespace.tag.EncryptAlgorithmBeanDefinitionTag;
-import org.springframework.beans.factory.support.AbstractBeanDefinition;
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
-import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.xml.DomUtils;
-import org.w3c.dom.Element;
-
-import java.util.Properties;
-
-/**
- * Encrypt algorithm bean definition parser.
- */
-public final class EncryptAlgorithmBeanDefinitionParser extends AbstractBeanDefinitionParser {
-    
-    @Override
-    protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
-        BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(EncryptAlgorithmFactoryBean.class);
-        factory.addConstructorArgValue(element.getAttribute(EncryptAlgorithmBeanDefinitionTag.TYPE_ATTRIBUTE));
-        factory.addConstructorArgValue(parseProperties(element, parserContext));
-        return factory.getBeanDefinition();
-    }
-    
-    private static Properties parseProperties(final Element element, final ParserContext parserContext) {
-        Element propsElement = DomUtils.getChildElementByTagName(element, EncryptAlgorithmBeanDefinitionTag.PROPS_TAG);
-        return null == propsElement ? new Properties() : parserContext.getDelegate().parsePropsElement(propsElement);
-    }
-}
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/parser/EncryptRuleBeanDefinitionParser.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/parser/EncryptRuleBeanDefinitionParser.java
index 5e40667..554de09 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/parser/EncryptRuleBeanDefinitionParser.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/parser/EncryptRuleBeanDefinitionParser.java
@@ -17,17 +17,16 @@
 
 package org.apache.shardingsphere.encrypt.spring.namespace.parser;
 
-import com.google.common.base.Strings;
 import org.apache.shardingsphere.encrypt.algorithm.config.AlgorithmProvidedEncryptRuleConfiguration;
 import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
 import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
+import org.apache.shardingsphere.encrypt.spring.namespace.factorybean.EncryptAlgorithmFactoryBean;
 import org.apache.shardingsphere.encrypt.spring.namespace.tag.EncryptRuleBeanDefinitionTag;
+import org.apache.shardingsphere.spring.namespace.parser.ShardingSphereAlgorithmBeanRegistry;
 import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.config.RuntimeBeanReference;
 import org.springframework.beans.factory.support.AbstractBeanDefinition;
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
 import org.springframework.beans.factory.support.ManagedList;
-import org.springframework.beans.factory.support.ManagedMap;
 import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
 import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate;
 import org.springframework.beans.factory.xml.ParserContext;
@@ -35,10 +34,7 @@ import org.springframework.util.xml.DomUtils;
 import org.w3c.dom.Element;
 
 import java.util.Collection;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
 
 /**
  * Encrypt rule bean definition parser.
@@ -48,33 +44,11 @@ public final class EncryptRuleBeanDefinitionParser extends AbstractBeanDefinitio
     @Override
     protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
         BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(AlgorithmProvidedEncryptRuleConfiguration.class);
-        factory.addConstructorArgValue(parseEncryptAlgorithmConfigurations(element));
         factory.addConstructorArgValue(parseEncryptTableRuleConfigurations(element));
+        factory.addConstructorArgValue(ShardingSphereAlgorithmBeanRegistry.getAlgorithmBeanReferences(parserContext, EncryptAlgorithmFactoryBean.class));
         return factory.getBeanDefinition();
     }
     
-    private Map<String, RuntimeBeanReference> parseEncryptAlgorithmConfigurations(final Element element) {
-        Collection<String> encryptAlgorithmRefs = findEncryptAlgorithmRefs(DomUtils.getChildElementsByTagName(element, EncryptRuleBeanDefinitionTag.TABLE_TAG));
-        Map<String, RuntimeBeanReference> result = new ManagedMap<>(encryptAlgorithmRefs.size());
-        for (String each : encryptAlgorithmRefs) {
-            result.put(each, new RuntimeBeanReference(each));
-        }
-        return result;
-    }
-    
-    private Collection<String> findEncryptAlgorithmRefs(final List<Element> encryptTableElements) {
-        Collection<String> result = new HashSet<>();
-        for (Element each : encryptTableElements) {
-            result.addAll(findEncryptAlgorithmRefsFromColumn(DomUtils.getChildElementsByTagName(each, EncryptRuleBeanDefinitionTag.COLUMN_TAG)));
-        }
-        return result;
-    }
-    
-    private Collection<String> findEncryptAlgorithmRefsFromColumn(final List<Element> encryptColumnElements) {
-        return encryptColumnElements.stream().filter(each -> !Strings.isNullOrEmpty(each.getAttribute(EncryptRuleBeanDefinitionTag.ENCRYPT_ALGORITHM_REF_ATTRIBUTE)))
-                .map(each -> each.getAttribute(EncryptRuleBeanDefinitionTag.ENCRYPT_ALGORITHM_REF_ATTRIBUTE)).collect(Collectors.toSet());
-    }
-    
     private static Collection<BeanDefinition> parseEncryptTableRuleConfigurations(final Element element) {
         List<Element> encryptTableElements = DomUtils.getChildElementsByTagName(element, EncryptRuleBeanDefinitionTag.TABLE_TAG);
         Collection<BeanDefinition> result = new ManagedList<>(encryptTableElements.size());
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/tag/EncryptAlgorithmBeanDefinitionTag.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/tag/EncryptAlgorithmBeanDefinitionTag.java
index 2082dd1..83711ba 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/tag/EncryptAlgorithmBeanDefinitionTag.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/tag/EncryptAlgorithmBeanDefinitionTag.java
@@ -23,8 +23,4 @@ package org.apache.shardingsphere.encrypt.spring.namespace.tag;
 public final class EncryptAlgorithmBeanDefinitionTag {
     
     public static final String ROOT_TAG = "encrypt-algorithm";
-    
-    public static final String TYPE_ATTRIBUTE = "type";
-    
-    public static final String PROPS_TAG = "props";
 }
diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/pom.xml b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/pom.xml
index 9dfafc7..ca468c0 100644
--- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/pom.xml
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/pom.xml
@@ -34,6 +34,11 @@
             <artifactId>shardingsphere-master-slave-common</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-jdbc-spring-namespace-infra</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         
         <dependency>
             <groupId>org.springframework</groupId>
diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/factorybean/MasterSlaveLoadBalanceAlgorithmFactoryBean.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/factorybean/Mast [...]
index 24069df..4368b80 100644
--- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/factorybean/MasterSlaveLoadBalanceAlgorithmFactoryBean.java
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/factorybean/MasterSlaveLoadBalanceAlgorithmFactoryBean.java
@@ -17,40 +17,22 @@
 
 package org.apache.shardingsphere.masterslave.spring.namespace.factorybean;
 
-import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.spi.type.TypedSPIRegistry;
 import org.apache.shardingsphere.masterslave.spi.MasterSlaveLoadBalanceAlgorithm;
-import org.springframework.beans.factory.FactoryBean;
+import org.apache.shardingsphere.spring.namespace.factorybean.ShardingSphereAlgorithmFactoryBean;
 
 import java.util.Properties;
 
 /**
  * Master-slave load balance algorithm factory bean.
  */
-@RequiredArgsConstructor
-public final class MasterSlaveLoadBalanceAlgorithmFactoryBean implements FactoryBean<MasterSlaveLoadBalanceAlgorithm> {
+public final class MasterSlaveLoadBalanceAlgorithmFactoryBean extends ShardingSphereAlgorithmFactoryBean<MasterSlaveLoadBalanceAlgorithm> {
     
     static {
         ShardingSphereServiceLoader.register(MasterSlaveLoadBalanceAlgorithm.class);
     }
     
-    private final String type;
-    
-    private final Properties props;
-    
-    @Override
-    public MasterSlaveLoadBalanceAlgorithm getObject() {
-        return TypedSPIRegistry.getRegisteredService(MasterSlaveLoadBalanceAlgorithm.class, type, props);
-    }
-    
-    @Override
-    public Class<?> getObjectType() {
-        return MasterSlaveLoadBalanceAlgorithm.class;
-    }
-    
-    @Override
-    public boolean isSingleton() {
-        return true;
+    public MasterSlaveLoadBalanceAlgorithmFactoryBean(final String type, final Properties props) {
+        super(type, props, MasterSlaveLoadBalanceAlgorithm.class);
     }
 }
diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/handler/MasterSlaveNamespaceHandler.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/handler/MasterSlaveNamespaceHandler.java
index 856f6ef..2eaf491 100644
--- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/handler/MasterSlaveNamespaceHandler.java
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/handler/MasterSlaveNamespaceHandler.java
@@ -17,10 +17,11 @@
 
 package org.apache.shardingsphere.masterslave.spring.namespace.handler;
 
-import org.apache.shardingsphere.masterslave.spring.namespace.parser.MasterSlaveLoadBalanceAlgorithmBeanDefinitionParser;
+import org.apache.shardingsphere.masterslave.spring.namespace.factorybean.MasterSlaveLoadBalanceAlgorithmFactoryBean;
 import org.apache.shardingsphere.masterslave.spring.namespace.parser.MasterSlaveRuleBeanDefinitionParser;
 import org.apache.shardingsphere.masterslave.spring.namespace.tag.LoadBalanceAlgorithmBeanDefinitionTag;
 import org.apache.shardingsphere.masterslave.spring.namespace.tag.MasterSlaveRuleBeanDefinitionTag;
+import org.apache.shardingsphere.spring.namespace.parser.ShardingSphereAlgorithmBeanDefinitionParser;
 import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
 
 /**
@@ -31,6 +32,6 @@ public final class MasterSlaveNamespaceHandler extends NamespaceHandlerSupport {
     @Override
     public void init() {
         registerBeanDefinitionParser(MasterSlaveRuleBeanDefinitionTag.ROOT_TAG, new MasterSlaveRuleBeanDefinitionParser());
-        registerBeanDefinitionParser(LoadBalanceAlgorithmBeanDefinitionTag.ROOT_TAG, new MasterSlaveLoadBalanceAlgorithmBeanDefinitionParser());
+        registerBeanDefinitionParser(LoadBalanceAlgorithmBeanDefinitionTag.ROOT_TAG, new ShardingSphereAlgorithmBeanDefinitionParser(MasterSlaveLoadBalanceAlgorithmFactoryBean.class));
     }
 }
diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/parser/MasterSlaveLoadBalanceAlgorithmBeanDefinitionParser.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/parser/Maste [...]
deleted file mode 100644
index 2dbb4de..0000000
--- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/parser/MasterSlaveLoadBalanceAlgorithmBeanDefinitionParser.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.masterslave.spring.namespace.parser;
-
-import org.apache.shardingsphere.masterslave.spring.namespace.factorybean.MasterSlaveLoadBalanceAlgorithmFactoryBean;
-import org.apache.shardingsphere.masterslave.spring.namespace.tag.LoadBalanceAlgorithmBeanDefinitionTag;
-import org.springframework.beans.factory.support.AbstractBeanDefinition;
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
-import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.xml.DomUtils;
-import org.w3c.dom.Element;
-
-import java.util.Properties;
-
-/**
- * Master slave load balance algorithm bean definition parser.
- */
-public final class MasterSlaveLoadBalanceAlgorithmBeanDefinitionParser extends AbstractBeanDefinitionParser {
-    
-    @Override
-    protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
-        BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(MasterSlaveLoadBalanceAlgorithmFactoryBean.class);
-        factory.addConstructorArgValue(element.getAttribute(LoadBalanceAlgorithmBeanDefinitionTag.TYPE_ATTRIBUTE));
-        factory.addConstructorArgValue(parseProperties(element, parserContext));
-        return factory.getBeanDefinition();
-    }
-    
-    private static Properties parseProperties(final Element element, final ParserContext parserContext) {
-        Element propsElement = DomUtils.getChildElementByTagName(element, LoadBalanceAlgorithmBeanDefinitionTag.PROPS_TAG);
-        return null == propsElement ? new Properties() : parserContext.getDelegate().parsePropsElement(propsElement);
-    }
-}
diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/parser/MasterSlaveRuleBeanDefinitionParser.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/parser/MasterSlaveRuleBeanDe [...]
index ab90b51..abbe67d 100644
--- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/parser/MasterSlaveRuleBeanDefinitionParser.java
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/parser/MasterSlaveRuleBeanDefinitionParser.java
@@ -18,16 +18,15 @@
 package org.apache.shardingsphere.masterslave.spring.namespace.parser;
 
 import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
-import org.apache.shardingsphere.masterslave.api.config.rule.MasterSlaveDataSourceRuleConfiguration;
 import org.apache.shardingsphere.masterslave.algorithm.config.AlgorithmProvidedMasterSlaveRuleConfiguration;
+import org.apache.shardingsphere.masterslave.api.config.rule.MasterSlaveDataSourceRuleConfiguration;
+import org.apache.shardingsphere.masterslave.spring.namespace.factorybean.MasterSlaveLoadBalanceAlgorithmFactoryBean;
 import org.apache.shardingsphere.masterslave.spring.namespace.tag.MasterSlaveRuleBeanDefinitionTag;
+import org.apache.shardingsphere.spring.namespace.parser.ShardingSphereAlgorithmBeanRegistry;
 import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.config.RuntimeBeanReference;
 import org.springframework.beans.factory.support.AbstractBeanDefinition;
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
 import org.springframework.beans.factory.support.ManagedList;
-import org.springframework.beans.factory.support.ManagedMap;
 import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
 import org.springframework.beans.factory.xml.ParserContext;
 import org.springframework.util.xml.DomUtils;
@@ -35,8 +34,6 @@ import org.w3c.dom.Element;
 
 import java.util.Collection;
 import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
 
 /**
  * Master-slave rule bean definition parser.
@@ -47,7 +44,7 @@ public final class MasterSlaveRuleBeanDefinitionParser extends AbstractBeanDefin
     protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
         BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(AlgorithmProvidedMasterSlaveRuleConfiguration.class);
         factory.addConstructorArgValue(parseMasterSlaveDataSourceRuleConfigurations(element));
-        factory.addConstructorArgValue(parseLoadBalanceAlgorithmsConfigurations(element));
+        factory.addConstructorArgValue(ShardingSphereAlgorithmBeanRegistry.getAlgorithmBeanReferences(parserContext, MasterSlaveLoadBalanceAlgorithmFactoryBean.class));
         return factory.getBeanDefinition();
     }
     
@@ -75,18 +72,4 @@ public final class MasterSlaveRuleBeanDefinitionParser extends AbstractBeanDefin
         result.addAll(slaveDataSources);
         return result;
     }
-    
-    private Map<String, RuntimeBeanReference> parseLoadBalanceAlgorithmsConfigurations(final Element element) {
-        Collection<String> loadBalanceAlgorithmRefs = findLoadBalanceAlgorithmRefs(DomUtils.getChildElementsByTagName(element, MasterSlaveRuleBeanDefinitionTag.DATA_SOURCE_TAG));
-        Map<String, RuntimeBeanReference> result = new ManagedMap<>(loadBalanceAlgorithmRefs.size());
-        for (String each : loadBalanceAlgorithmRefs) {
-            result.put(each, new RuntimeBeanReference(each));
-        }
-        return result;
-    }
-    
-    private Collection<String> findLoadBalanceAlgorithmRefs(final List<Element> masterSlaveDataSourceElements) {
-        return masterSlaveDataSourceElements.stream().filter(each -> !Strings.isNullOrEmpty(each.getAttribute(MasterSlaveRuleBeanDefinitionTag.LOAD_BALANCE_ALGORITHM_REF_ATTRIBUTE)))
-                .map(each -> each.getAttribute(MasterSlaveRuleBeanDefinitionTag.LOAD_BALANCE_ALGORITHM_REF_ATTRIBUTE)).collect(Collectors.toSet());
-    }
 }
diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/tag/LoadBalanceAlgorithmBeanDefinitionTag.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/tag/LoadBalanceAlgorithmBeanD [...]
index 5ec17df..24897cf 100644
--- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/tag/LoadBalanceAlgorithmBeanDefinitionTag.java
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/tag/LoadBalanceAlgorithmBeanDefinitionTag.java
@@ -23,8 +23,4 @@ package org.apache.shardingsphere.masterslave.spring.namespace.tag;
 public final class LoadBalanceAlgorithmBeanDefinitionTag {
     
     public static final String ROOT_TAG = "load-balance-algorithm";
-    
-    public static final String TYPE_ATTRIBUTE = "type";
-    
-    public static final String PROPS_TAG = "props";
 }
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfiguration.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfiguration.java
index 3c9af6b..4e4a394 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfiguration.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfiguration.java
@@ -39,9 +39,9 @@ import java.util.Map;
 public final class ShardingRuleConfiguration implements RuleConfiguration {
     
     private Collection<ShardingTableRuleConfiguration> tables = new LinkedList<>();
-
+    
     private Collection<ShardingAutoTableRuleConfiguration> autoTables = new LinkedList<>();
-
+    
     private Collection<String> bindingTableGroups = new LinkedList<>();
     
     private Collection<String> broadcastTables = new LinkedList<>();
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/spi/ShardingAlgorithm.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/spi/ShardingAlgorithm.java
index dac1ce4..03d6aa7 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/spi/ShardingAlgorithm.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/spi/ShardingAlgorithm.java
@@ -17,11 +17,11 @@
 
 package org.apache.shardingsphere.sharding.spi;
 
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithm;
 import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmPostProcessor;
-import org.apache.shardingsphere.infra.spi.type.TypedSPI;
 
 /**
  * Sharding algorithm.
  */
-public interface ShardingAlgorithm extends TypedSPI, ShardingSphereAlgorithmPostProcessor {
+public interface ShardingAlgorithm extends ShardingSphereAlgorithm, ShardingSphereAlgorithmPostProcessor {
 }
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/strategy/algorithm/keygen/config/AlgorithmProvidedShardingRuleConfiguration.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/strategy/algorithm/keygen/config/AlgorithmProvidedShardingRuleConfiguration.java
index 3a7bfcd..97cb7cc 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/strategy/algorithm/keygen/config/AlgorithmProvidedShardingRuleConfiguration.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/strategy/algorithm/keygen/config/AlgorithmProvidedShardingRuleConfiguration.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.sharding.strategy.algorithm.keygen.config;
 
 import lombok.Getter;
-import lombok.Setter;
+import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
 import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
@@ -27,29 +27,28 @@ import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingS
 import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
 
 import java.util.Collection;
-import java.util.LinkedList;
 import java.util.Map;
 
 /**
  * Algorithm provided sharding rule configuration.
  */
+@RequiredArgsConstructor
 @Getter
-@Setter
 public final class AlgorithmProvidedShardingRuleConfiguration implements RuleConfiguration {
     
-    private Collection<ShardingTableRuleConfiguration> tables = new LinkedList<>();
+    private final Collection<ShardingTableRuleConfiguration> tables;
     
-    private Collection<ShardingAutoTableRuleConfiguration> autoTables = new LinkedList<>();
+    private final Collection<ShardingAutoTableRuleConfiguration> autoTables;
     
-    private Collection<String> bindingTableGroups = new LinkedList<>();
+    private final Collection<String> bindingTableGroups;
     
-    private Collection<String> broadcastTables = new LinkedList<>();
+    private final Collection<String> broadcastTables;
     
-    private ShardingStrategyConfiguration defaultDatabaseShardingStrategy;
+    private final ShardingStrategyConfiguration defaultDatabaseShardingStrategy;
     
-    private ShardingStrategyConfiguration defaultTableShardingStrategy;
+    private final ShardingStrategyConfiguration defaultTableShardingStrategy;
     
-    private KeyGenerateStrategyConfiguration defaultKeyGenerateStrategy;
+    private final KeyGenerateStrategyConfiguration defaultKeyGenerateStrategy;
     
-    private Map<String, KeyGenerateAlgorithm> keyGenerators;
+    private final Map<String, KeyGenerateAlgorithm> keyGenerators;
 }
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/pom.xml b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/pom.xml
index 36dd3ec..a8a53e5 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/pom.xml
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/pom.xml
@@ -34,6 +34,11 @@
             <artifactId>shardingsphere-sharding-common</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-jdbc-spring-namespace-infra</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         
         <dependency>
             <groupId>org.springframework</groupId>
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/factorybean/KeyGenerateAlgorithmFactoryBean.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/factorybean/KeyGenerateAlgorithmFactoryBean.java
index a5666b7..919f8b7 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/factorybean/KeyGenerateAlgorithmFactoryBean.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/factorybean/KeyGenerateAlgorithmFactoryBean.java
@@ -17,46 +17,22 @@
 
 package org.apache.shardingsphere.sharding.spring.namespace.factorybean;
 
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
 import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.spi.type.TypedSPIRegistry;
 import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-import org.springframework.beans.factory.FactoryBean;
+import org.apache.shardingsphere.spring.namespace.factorybean.ShardingSphereAlgorithmFactoryBean;
 
 import java.util.Properties;
 
 /**
  * Key generate algorithm factory bean.
  */
-public final class KeyGenerateAlgorithmFactoryBean implements FactoryBean<KeyGenerateAlgorithm> {
+public final class KeyGenerateAlgorithmFactoryBean extends ShardingSphereAlgorithmFactoryBean<KeyGenerateAlgorithm> {
     
     static {
         ShardingSphereServiceLoader.register(KeyGenerateAlgorithm.class);
     }
     
-    private String type;
-    
-    private Properties props;
-    
     public KeyGenerateAlgorithmFactoryBean(final String type, final Properties props) {
-        Preconditions.checkArgument(!Strings.isNullOrEmpty(type), "The type of keyGenerateAlgorithm is required.");
-        this.type = type;
-        this.props = props;
-    }
-    
-    @Override
-    public KeyGenerateAlgorithm getObject() {
-        return TypedSPIRegistry.getRegisteredService(KeyGenerateAlgorithm.class, type, props);
-    }
-    
-    @Override
-    public Class<?> getObjectType() {
-        return KeyGenerateAlgorithm.class;
-    }
-    
-    @Override
-    public boolean isSingleton() {
-        return true;
+        super(type, props, KeyGenerateAlgorithm.class);
     }
 }
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/factorybean/ShardingAlgorithmFactoryBean.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/factorybean/ShardingAlgorithmFactoryBean.java
index 757b147..aff56d9 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/factorybean/ShardingAlgorithmFactoryBean.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/factorybean/ShardingAlgorithmFactoryBean.java
@@ -17,46 +17,22 @@
 
 package org.apache.shardingsphere.sharding.spring.namespace.factorybean;
 
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
 import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.spi.type.TypedSPIRegistry;
 import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
-import org.springframework.beans.factory.FactoryBean;
+import org.apache.shardingsphere.spring.namespace.factorybean.ShardingSphereAlgorithmFactoryBean;
 
 import java.util.Properties;
 
 /**
  * Sharding algorithm factory bean.
  */
-public final class ShardingAlgorithmFactoryBean implements FactoryBean<ShardingAlgorithm> {
+public final class ShardingAlgorithmFactoryBean extends ShardingSphereAlgorithmFactoryBean<ShardingAlgorithm> {
 
     static {
         ShardingSphereServiceLoader.register(ShardingAlgorithm.class);
     }
-
-    private String type;
-
-    private Properties props;
-
+    
     public ShardingAlgorithmFactoryBean(final String type, final Properties props) {
-        Preconditions.checkArgument(!Strings.isNullOrEmpty(type), "The type of shardingAlgorithm is required.");
-        this.type = type;
-        this.props = props;
-    }
-
-    @Override
-    public ShardingAlgorithm getObject() {
-        return TypedSPIRegistry.getRegisteredService(ShardingAlgorithm.class, type, props);
-    }
-
-    @Override
-    public Class<?> getObjectType() {
-        return ShardingAlgorithm.class;
-    }
-
-    @Override
-    public boolean isSingleton() {
-        return true;
+        super(type, props, ShardingAlgorithm.class);
     }
 }
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/handler/ShardingNamespaceHandler.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/handler/ShardingNamespaceHandler.java
index af6cf6b..98479e8 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/handler/ShardingNamespaceHandler.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/handler/ShardingNamespaceHandler.java
@@ -17,8 +17,8 @@
 
 package org.apache.shardingsphere.sharding.spring.namespace.handler;
 
-import org.apache.shardingsphere.sharding.spring.namespace.parser.algorithm.KeyGenerateAlgorithmBeanDefinitionParser;
-import org.apache.shardingsphere.sharding.spring.namespace.parser.algorithm.ShardingAlgorithmBeanDefinitionParser;
+import org.apache.shardingsphere.sharding.spring.namespace.factorybean.KeyGenerateAlgorithmFactoryBean;
+import org.apache.shardingsphere.sharding.spring.namespace.factorybean.ShardingAlgorithmFactoryBean;
 import org.apache.shardingsphere.sharding.spring.namespace.parser.rule.ShardingRuleBeanDefinitionParser;
 import org.apache.shardingsphere.sharding.spring.namespace.parser.strategy.KeyGenerateStrategyBeanDefinitionParser;
 import org.apache.shardingsphere.sharding.spring.namespace.parser.strategy.ShardingStrategyBeanDefinitionParser;
@@ -27,6 +27,7 @@ import org.apache.shardingsphere.sharding.spring.namespace.tag.algorithm.Shardin
 import org.apache.shardingsphere.sharding.spring.namespace.tag.rule.ShardingRuleBeanDefinitionTag;
 import org.apache.shardingsphere.sharding.spring.namespace.tag.strategy.KeyGenerateStrategyBeanDefinitionTag;
 import org.apache.shardingsphere.sharding.spring.namespace.tag.strategy.ShardingStrategyBeanDefinitionTag;
+import org.apache.shardingsphere.spring.namespace.parser.ShardingSphereAlgorithmBeanDefinitionParser;
 import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
 
 /**
@@ -41,8 +42,8 @@ public final class ShardingNamespaceHandler extends NamespaceHandlerSupport {
         registerBeanDefinitionParser(ShardingStrategyBeanDefinitionTag.COMPLEX_STRATEGY_ROOT_TAG, new ShardingStrategyBeanDefinitionParser());
         registerBeanDefinitionParser(ShardingStrategyBeanDefinitionTag.HINT_STRATEGY_ROOT_TAG, new ShardingStrategyBeanDefinitionParser());
         registerBeanDefinitionParser(ShardingStrategyBeanDefinitionTag.NONE_STRATEGY_ROOT_TAG, new ShardingStrategyBeanDefinitionParser());
-        registerBeanDefinitionParser(ShardingAlgorithmBeanDefinitionTag.ROOT_TAG, new ShardingAlgorithmBeanDefinitionParser());
+        registerBeanDefinitionParser(ShardingAlgorithmBeanDefinitionTag.ROOT_TAG, new ShardingSphereAlgorithmBeanDefinitionParser(ShardingAlgorithmFactoryBean.class));
         registerBeanDefinitionParser(KeyGenerateStrategyBeanDefinitionTag.ROOT_TAG, new KeyGenerateStrategyBeanDefinitionParser());
-        registerBeanDefinitionParser(KeyGenerateAlgorithmBeanDefinitionTag.ROOT_TAG, new KeyGenerateAlgorithmBeanDefinitionParser());
+        registerBeanDefinitionParser(KeyGenerateAlgorithmBeanDefinitionTag.ROOT_TAG, new ShardingSphereAlgorithmBeanDefinitionParser(KeyGenerateAlgorithmFactoryBean.class));
     }
 }
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/parser/algorithm/KeyGenerateAlgorithmBeanDefinitionParser.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/parser/algorithm/KeyGenerateAlgorithmBeanDe [...]
deleted file mode 100644
index 69369ea..0000000
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/parser/algorithm/KeyGenerateAlgorithmBeanDefinitionParser.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.sharding.spring.namespace.parser.algorithm;
-
-import org.apache.shardingsphere.sharding.spring.namespace.factorybean.KeyGenerateAlgorithmFactoryBean;
-import org.apache.shardingsphere.sharding.spring.namespace.tag.algorithm.KeyGenerateAlgorithmBeanDefinitionTag;
-import org.springframework.beans.factory.support.AbstractBeanDefinition;
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
-import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.util.xml.DomUtils;
-import org.w3c.dom.Element;
-
-import java.util.Properties;
-
-/**
- * Key generate algorithm bean parser for spring namespace.
- */
-public final class KeyGenerateAlgorithmBeanDefinitionParser extends AbstractBeanDefinitionParser {
-    
-    @Override
-    protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
-        BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(KeyGenerateAlgorithmFactoryBean.class);
-        factory.addConstructorArgValue(element.getAttribute(KeyGenerateAlgorithmBeanDefinitionTag.TYPE_ATTRIBUTE));
-        factory.addConstructorArgValue(parseProperties(element, parserContext));
-        return factory.getBeanDefinition();
-    }
-    
-    private Properties parseProperties(final Element element, final ParserContext parserContext) {
-        Element propsElement = DomUtils.getChildElementByTagName(element, KeyGenerateAlgorithmBeanDefinitionTag.PROPS_TAG);
-        return null == propsElement ? new Properties() : parserContext.getDelegate().parsePropsElement(propsElement);
-    }
-}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/parser/rule/ShardingRuleBeanDefinitionParser.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/parser/rule/ShardingRuleBeanDefinitionParser.java
index 066975e..88204d5 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/parser/rule/ShardingRuleBeanDefinitionParser.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/parser/rule/ShardingRuleBeanDefinitionParser.java
@@ -23,23 +23,20 @@ import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfi
 import org.apache.shardingsphere.sharding.spring.namespace.factorybean.KeyGenerateAlgorithmFactoryBean;
 import org.apache.shardingsphere.sharding.spring.namespace.tag.rule.ShardingRuleBeanDefinitionTag;
 import org.apache.shardingsphere.sharding.strategy.algorithm.keygen.config.AlgorithmProvidedShardingRuleConfiguration;
+import org.apache.shardingsphere.spring.namespace.parser.ShardingSphereAlgorithmBeanRegistry;
 import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.config.RuntimeBeanReference;
 import org.springframework.beans.factory.support.AbstractBeanDefinition;
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
 import org.springframework.beans.factory.support.ManagedList;
-import org.springframework.beans.factory.support.ManagedMap;
 import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
 import org.springframework.beans.factory.xml.ParserContext;
 import org.springframework.util.xml.DomUtils;
 import org.w3c.dom.Element;
 
-import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
+import java.util.Optional;
 
 /**
  * Sharding rule parser for spring namespace.
@@ -49,42 +46,21 @@ public final class ShardingRuleBeanDefinitionParser extends AbstractBeanDefiniti
     @Override
     protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
         BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(AlgorithmProvidedShardingRuleConfiguration.class);
-        parseDefaultDatabaseShardingStrategy(factory, element);
-        parseDefaultTableShardingStrategy(factory, element);
-        factory.addPropertyValue("tables", parseTableRulesConfiguration(element));
-        factory.addPropertyValue("autoTables", parseAutoTableRulesConfiguration(element));
-        factory.addPropertyValue("bindingTableGroups", parseBindingTablesConfiguration(element));
-        factory.addPropertyValue("broadcastTables", parseBroadcastTables(element));
-        parseDefaultKeyGenerateStrategy(factory, element);
-        factory.addPropertyValue("keyGenerators", getKeyGenerateAlgorithmBeanRefs(parserContext));
+        factory.addConstructorArgValue(parseTableRulesConfiguration(element));
+        factory.addConstructorArgValue(parseAutoTableRulesConfiguration(element));
+        factory.addConstructorArgValue(parseBindingTablesConfiguration(element));
+        factory.addConstructorArgValue(parseBroadcastTables(element));
+        addDefaultDatabaseShardingStrategyRef(element, factory);
+        addDefaultTableShardingStrategyRef(element, factory);
+        addDefaultKeyGenerateStrategyRef(element, factory);
+        factory.addConstructorArgValue(ShardingSphereAlgorithmBeanRegistry.getAlgorithmBeanReferences(parserContext, KeyGenerateAlgorithmFactoryBean.class));
         return factory.getBeanDefinition();
     }
     
-    private void parseDefaultKeyGenerateStrategy(final BeanDefinitionBuilder factory, final Element element) {
-        String defaultKeyGeneratorConfig = element.getAttribute(ShardingRuleBeanDefinitionTag.DEFAULT_KEY_GENERATE_STRATEGY_REF_ATTRIBUTE);
-        if (!Strings.isNullOrEmpty(defaultKeyGeneratorConfig)) {
-            factory.addPropertyReference("defaultKeyGenerateStrategy", defaultKeyGeneratorConfig);
-        }
-    }
-    
-    private void parseDefaultDatabaseShardingStrategy(final BeanDefinitionBuilder factory, final Element element) {
-        String defaultDatabaseShardingStrategy = element.getAttribute(ShardingRuleBeanDefinitionTag.DEFAULT_DATABASE_STRATEGY_REF_ATTRIBUTE);
-        if (!Strings.isNullOrEmpty(defaultDatabaseShardingStrategy)) {
-            factory.addPropertyReference("defaultDatabaseShardingStrategy", defaultDatabaseShardingStrategy);
-        }
-    }
-    
-    private void parseDefaultTableShardingStrategy(final BeanDefinitionBuilder factory, final Element element) {
-        String defaultTableShardingStrategy = element.getAttribute(ShardingRuleBeanDefinitionTag.DEFAULT_TABLE_STRATEGY_REF_ATTRIBUTE);
-        if (!Strings.isNullOrEmpty(defaultTableShardingStrategy)) {
-            factory.addPropertyReference("defaultTableShardingStrategy", defaultTableShardingStrategy);
-        }
-    }
-    
     private List<BeanDefinition> parseTableRulesConfiguration(final Element element) {
         Element tableRulesElement = DomUtils.getChildElementByTagName(element, ShardingRuleBeanDefinitionTag.TABLE_RULES_TAG);
         if (null == tableRulesElement) {
-            return new LinkedList<>();
+            return Collections.emptyList();
         }
         List<Element> tableRuleElements = DomUtils.getChildElementsByTagName(tableRulesElement, ShardingRuleBeanDefinitionTag.TABLE_RULE_TAG);
         List<BeanDefinition> result = new ManagedList<>(tableRuleElements.size());
@@ -93,7 +69,7 @@ public final class ShardingRuleBeanDefinitionParser extends AbstractBeanDefiniti
         }
         return result;
     }
-
+    
     private BeanDefinition parseTableRuleConfiguration(final Element tableElement) {
         BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(ShardingTableRuleConfiguration.class);
         factory.addConstructorArgValue(tableElement.getAttribute(ShardingRuleBeanDefinitionTag.LOGIC_TABLE_ATTRIBUTE));
@@ -124,11 +100,11 @@ public final class ShardingRuleBeanDefinitionParser extends AbstractBeanDefiniti
             factory.addPropertyReference("tableShardingStrategy", tableStrategy);
         }
     }
-
+    
     private List<BeanDefinition> parseAutoTableRulesConfiguration(final Element element) {
         Element tableRulesElement = DomUtils.getChildElementByTagName(element, ShardingRuleBeanDefinitionTag.AUTO_TABLE_RULES_TAG);
         if (null == tableRulesElement) {
-            return new LinkedList<>();
+            return Collections.emptyList();
         }
         List<Element> tableRuleElements = DomUtils.getChildElementsByTagName(tableRulesElement, ShardingRuleBeanDefinitionTag.AUTO_TABLE_RULE_TAG);
         List<BeanDefinition> result = new ManagedList<>(tableRuleElements.size());
@@ -137,7 +113,7 @@ public final class ShardingRuleBeanDefinitionParser extends AbstractBeanDefiniti
         }
         return result;
     }
-
+    
     private BeanDefinition parseAutoTableRuleConfiguration(final Element tableElement) {
         BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(ShardingAutoTableRuleConfiguration.class);
         factory.addConstructorArgValue(tableElement.getAttribute(ShardingRuleBeanDefinitionTag.LOGIC_TABLE_ATTRIBUTE));
@@ -146,14 +122,14 @@ public final class ShardingRuleBeanDefinitionParser extends AbstractBeanDefiniti
         parseKeyGenerateStrategyConfiguration(tableElement, factory);
         return factory.getBeanDefinition();
     }
-
+    
     private void parseActualDataSources(final Element tableElement, final BeanDefinitionBuilder factory) {
         String actualDataNodes = tableElement.getAttribute(ShardingRuleBeanDefinitionTag.ACTUAL_DATA_SOURCES_ATTRIBUTE);
         if (!Strings.isNullOrEmpty(actualDataNodes)) {
             factory.addConstructorArgValue(actualDataNodes);
         }
     }
-
+    
     private void parseShardingStrategyConfiguration(final Element tableElement, final BeanDefinitionBuilder factory) {
         String databaseStrategy = tableElement.getAttribute(ShardingRuleBeanDefinitionTag.SHARDING_STRATEGY_REF_ATTRIBUTE);
         if (!Strings.isNullOrEmpty(databaseStrategy)) {
@@ -194,32 +170,35 @@ public final class ShardingRuleBeanDefinitionParser extends AbstractBeanDefiniti
         return result;
     }
     
-    private Map<String, RuntimeBeanReference> getKeyGenerateAlgorithmBeanRefs(final ParserContext parserContext) {
-        Map<String, RuntimeBeanReference> result = new ManagedMap<>();
-        for (String each : parserContext.getRegistry().getBeanDefinitionNames()) {
-            if (parserContext.getRegistry().getBeanDefinition(each).getBeanClassName().equals(KeyGenerateAlgorithmFactoryBean.class.getName())) {
-                result.put(each, new RuntimeBeanReference(each));
-            }
+    private void addDefaultDatabaseShardingStrategyRef(final Element element, final BeanDefinitionBuilder factory) {
+        Optional<String> strategyRef = parseStrategyRef(element, ShardingRuleBeanDefinitionTag.DEFAULT_DATABASE_STRATEGY_REF_ATTRIBUTE);
+        if (strategyRef.isPresent()) {
+            factory.addConstructorArgReference(strategyRef.get());
+        } else {
+            factory.addConstructorArgValue(null);
         }
-        return result;
     }
     
-    private Map<String, RuntimeBeanReference> parseKeyGenerateStrategyConfigurations(final Element element) {
-        Map<String, RuntimeBeanReference> result = new ManagedMap<>();
-        for (Element each : DomUtils.getChildElementsByTagName(element, ShardingRuleBeanDefinitionTag.TABLE_RULES_TAG)) {
-            for (String ref : findKeyGenerateStrategyRefsFromTable(DomUtils.getChildElementsByTagName(each, ShardingRuleBeanDefinitionTag.TABLE_RULE_TAG))) {
-                result.put(ref, new RuntimeBeanReference(ref));
-            }
+    private void addDefaultTableShardingStrategyRef(final Element element, final BeanDefinitionBuilder factory) {
+        Optional<String> strategyRef = parseStrategyRef(element, ShardingRuleBeanDefinitionTag.DEFAULT_TABLE_STRATEGY_REF_ATTRIBUTE);
+        if (strategyRef.isPresent()) {
+            factory.addConstructorArgReference(strategyRef.get());
+        } else {
+            factory.addConstructorArgValue(null);
         }
-        String defaultKeyGenerateStrategyRef = element.getAttribute(ShardingRuleBeanDefinitionTag.DEFAULT_KEY_GENERATE_STRATEGY_REF_ATTRIBUTE);
-        if (!Strings.isNullOrEmpty(defaultKeyGenerateStrategyRef)) {
-            result.put(defaultKeyGenerateStrategyRef, new RuntimeBeanReference(defaultKeyGenerateStrategyRef));
+    }
+    
+    private void addDefaultKeyGenerateStrategyRef(final Element element, final BeanDefinitionBuilder factory) {
+        Optional<String> strategyRef = parseStrategyRef(element, ShardingRuleBeanDefinitionTag.DEFAULT_KEY_GENERATE_STRATEGY_REF_ATTRIBUTE);
+        if (strategyRef.isPresent()) {
+            factory.addConstructorArgReference(strategyRef.get());
+        } else {
+            factory.addConstructorArgValue(null);
         }
-        return result;
     }
     
-    private Collection<String> findKeyGenerateStrategyRefsFromTable(final List<Element> shardingTableElements) {
-        return shardingTableElements.stream().filter(each -> !Strings.isNullOrEmpty(each.getAttribute(ShardingRuleBeanDefinitionTag.STRATEGY_REF_ATTRIBUTE)))
-                .map(each -> each.getAttribute(ShardingRuleBeanDefinitionTag.STRATEGY_REF_ATTRIBUTE)).collect(Collectors.toSet());
+    private Optional<String> parseStrategyRef(final Element element, final String tagName) {
+        String result = element.getAttribute(tagName);
+        return Strings.isNullOrEmpty(result) ? Optional.empty() : Optional.of(result);
     }
 }
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/tag/algorithm/KeyGenerateAlgorithmBeanDefinitionTag.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/tag/algorithm/KeyGenerateAlgorithmBeanDefinitionTag.java
index 3a42935..da6ad09 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/tag/algorithm/KeyGenerateAlgorithmBeanDefinitionTag.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/tag/algorithm/KeyGenerateAlgorithmBeanDefinitionTag.java
@@ -27,8 +27,4 @@ import lombok.NoArgsConstructor;
 public final class KeyGenerateAlgorithmBeanDefinitionTag {
     
     public static final String ROOT_TAG = "key-generate-algorithm";
-    
-    public static final String TYPE_ATTRIBUTE = "type";
-    
-    public static final String PROPS_TAG = "props";
 }
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/tag/algorithm/ShardingAlgorithmBeanDefinitionTag.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/tag/algorithm/ShardingAlgorithmBeanDefinitionTag.java
index 1a4321d..149d373 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/tag/algorithm/ShardingAlgorithmBeanDefinitionTag.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/tag/algorithm/ShardingAlgorithmBeanDefinitionTag.java
@@ -27,8 +27,4 @@ import lombok.NoArgsConstructor;
 public final class ShardingAlgorithmBeanDefinitionTag {
     
     public static final String ROOT_TAG = "sharding-algorithm";
-    
-    public static final String TYPE_ATTRIBUTE = "type";
-    
-    public static final String PROPS_TAG = "props";
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithmPostProcessor.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithmPostProcessor.java
index a2a973f..a00df16 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithmPostProcessor.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithmPostProcessor.java
@@ -19,8 +19,6 @@ package org.apache.shardingsphere.infra.config.algorithm;
 
 /**
  * ShardingSphere algorithm post processor.
- *
- * @author zhangliang
  */
 public interface ShardingSphereAlgorithmPostProcessor {
     
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/pom.xml b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/pom.xml
index cff1302..6056ebd 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/pom.xml
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/pom.xml
@@ -31,5 +31,6 @@
     
     <modules>
         <module>shardingsphere-jdbc-spring-boot-starter-infra</module>
+        <module>shardingsphere-jdbc-spring-namespace-infra</module>
     </modules>
 </project>
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/pom.xml b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-namespace-infra/pom.xml
similarity index 89%
copy from shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/pom.xml
copy to shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-namespace-infra/pom.xml
index e34301f..2848ea8 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/pom.xml
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-namespace-infra/pom.xml
@@ -22,16 +22,16 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.shardingsphere</groupId>
-        <artifactId>shardingsphere-encrypt-spring</artifactId>
+        <artifactId>shardingsphere-jdbc-spring-infra</artifactId>
         <version>5.0.0-RC1-SNAPSHOT</version>
     </parent>
-    <artifactId>shardingsphere-encrypt-spring-namespace</artifactId>
+    <artifactId>shardingsphere-jdbc-spring-namespace-infra</artifactId>
     <name>${project.artifactId}</name>
     
     <dependencies>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-encrypt-common</artifactId>
+            <artifactId>shardingsphere-infra-common</artifactId>
             <version>${project.version}</version>
         </dependency>
         
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/factorybean/EncryptAlgorithmFactoryBean.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-namespace-infra/src/main/java/org/apache/shardingsphere/spring/namespace/factorybean/ShardingSphereAlgorithmFactoryBean.java
similarity index 63%
copy from shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/factorybean/EncryptAlgorithmFactoryBean.java
copy to shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-namespace-infra/src/main/java/org/apache/shardingsphere/spring/namespace/factorybean/ShardingSphereAlgorithmFactoryBean.java
index 3707c12..cb294ec 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-namespace/src/main/java/org/apache/shardingsphere/encrypt/spring/namespace/factorybean/EncryptAlgorithmFactoryBean.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-namespace-infra/src/main/java/org/apache/shardingsphere/spring/namespace/factorybean/ShardingSphereAlgorithmFactoryBean.java
@@ -15,42 +15,36 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.encrypt.spring.namespace.factorybean;
+package org.apache.shardingsphere.spring.namespace.factorybean;
 
+import lombok.Getter;
 import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithm;
 import org.apache.shardingsphere.infra.spi.type.TypedSPIRegistry;
 import org.springframework.beans.factory.FactoryBean;
 
 import java.util.Properties;
 
 /**
- * Encrypt algorithm factory bean.
+ * ShardingSphere algorithm factory bean.
  */
 @RequiredArgsConstructor
-public final class EncryptAlgorithmFactoryBean implements FactoryBean<EncryptAlgorithm> {
-    
-    static {
-        ShardingSphereServiceLoader.register(EncryptAlgorithm.class);
-    }
+public abstract class ShardingSphereAlgorithmFactoryBean<T extends ShardingSphereAlgorithm> implements FactoryBean<T> {
     
     private final String type;
     
     private final Properties props;
     
-    @Override
-    public EncryptAlgorithm getObject() {
-        return TypedSPIRegistry.getRegisteredService(EncryptAlgorithm.class, type, props);
-    }
+    @Getter
+    private final Class<T> objectType;
     
     @Override
-    public Class<?> getObjectType() {
-        return EncryptAlgorithm.class;
+    public final T getObject() {
+        return TypedSPIRegistry.getRegisteredService(objectType, type, props);
     }
     
     @Override
-    public boolean isSingleton() {
+    public final boolean isSingleton() {
         return true;
     }
 }
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/parser/algorithm/ShardingAlgorithmBeanDefinitionParser.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-namespace-infra/src/main/java/org/apache/shardingsphere/spring/namespace/parser/ShardingSphereAlgorithmBeanDefinitionParser.java
similarity index 65%
rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/parser/algorithm/ShardingAlgorithmBeanDefinitionParser.java
rename to shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-namespace-infra/src/main/java/org/apache/shardingsphere/spring/namespace/parser/ShardingSphereAlgorithmBeanDefinitionParser.java
index 5c53220..1296558 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/parser/algorithm/ShardingAlgorithmBeanDefinitionParser.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-namespace-infra/src/main/java/org/apache/shardingsphere/spring/namespace/parser/ShardingSphereAlgorithmBeanDefinitionParser.java
@@ -15,10 +15,11 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.sharding.spring.namespace.parser.algorithm;
+package org.apache.shardingsphere.spring.namespace.parser;
 
-import org.apache.shardingsphere.sharding.spring.namespace.factorybean.ShardingAlgorithmFactoryBean;
-import org.apache.shardingsphere.sharding.spring.namespace.tag.algorithm.ShardingAlgorithmBeanDefinitionTag;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.spring.namespace.factorybean.ShardingSphereAlgorithmFactoryBean;
+import org.apache.shardingsphere.spring.namespace.tag.ShardingSphereAlgorithmBeanDefinitionTag;
 import org.springframework.beans.factory.support.AbstractBeanDefinition;
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
 import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
@@ -29,20 +30,23 @@ import org.w3c.dom.Element;
 import java.util.Properties;
 
 /**
- * Sharding algorithm bean parser for spring namespace.
+ * ShardingSphere algorithm bean parser for spring namespace.
  */
-public final class ShardingAlgorithmBeanDefinitionParser extends AbstractBeanDefinitionParser {
+@RequiredArgsConstructor
+public final class ShardingSphereAlgorithmBeanDefinitionParser extends AbstractBeanDefinitionParser {
+    
+    private final Class<? extends ShardingSphereAlgorithmFactoryBean> beanClass;
     
     @Override
     protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
-        BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(ShardingAlgorithmFactoryBean.class);
-        factory.addConstructorArgValue(element.getAttribute(ShardingAlgorithmBeanDefinitionTag.TYPE_ATTRIBUTE));
-        factory.addConstructorArgValue(parseProperties(element, parserContext));
+        BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(beanClass);
+        factory.addConstructorArgValue(element.getAttribute(ShardingSphereAlgorithmBeanDefinitionTag.TYPE_ATTRIBUTE));
+        factory.addConstructorArgValue(parsePropsElement(element, parserContext));
         return factory.getBeanDefinition();
     }
     
-    private Properties parseProperties(final Element element, final ParserContext parserContext) {
-        Element propsElement = DomUtils.getChildElementByTagName(element, ShardingAlgorithmBeanDefinitionTag.PROPS_TAG);
+    private Properties parsePropsElement(final Element element, final ParserContext parserContext) {
+        Element propsElement = DomUtils.getChildElementByTagName(element, ShardingSphereAlgorithmBeanDefinitionTag.PROPS_TAG);
         return null == propsElement ? new Properties() : parserContext.getDelegate().parsePropsElement(propsElement);
     }
 }
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-namespace-infra/src/main/java/org/apache/shardingsphere/spring/namespace/parser/ShardingSphereAlgorithmBeanRegistry.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-namespace-infra/src/main/java/org/apache/shardingsphere/spring/namespace/parser/ShardingSphereAlgorithmBeanRegistry.java
new file mode 100644
index 0000000..6dffcfd
--- /dev/null
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-namespace-infra/src/main/java/org/apache/shardingsphere/spring/namespace/parser/ShardingSphereAlgorithmBeanRegistry.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.spring.namespace.parser;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.spring.namespace.factorybean.ShardingSphereAlgorithmFactoryBean;
+import org.springframework.beans.factory.config.RuntimeBeanReference;
+import org.springframework.beans.factory.support.ManagedMap;
+import org.springframework.beans.factory.xml.ParserContext;
+
+import java.util.Map;
+
+/**
+ * ShardingSphere algorithm bean registry.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ShardingSphereAlgorithmBeanRegistry {
+    
+    /**
+     * Get algorithm bean references.
+     * 
+     * @param parserContext parser context for spring application context
+     * @param algorithmFactoryBeanClass ShardingSphere algorithm factory bean class
+     * @return ShardingSphere algorithm bean references
+     */
+    public static Map<String, RuntimeBeanReference> getAlgorithmBeanReferences(final ParserContext parserContext, final Class<? extends ShardingSphereAlgorithmFactoryBean> algorithmFactoryBeanClass) {
+        String[] beanDefinitionNames = parserContext.getRegistry().getBeanDefinitionNames();
+        String algorithmFactoryBeanClassName = algorithmFactoryBeanClass.getName();
+        Map<String, RuntimeBeanReference> result = new ManagedMap<>(beanDefinitionNames.length);
+        for (String each : beanDefinitionNames) {
+            if (parserContext.getRegistry().getBeanDefinition(each).getBeanClassName().equals(algorithmFactoryBeanClassName)) {
+                result.put(each, new RuntimeBeanReference(each));
+            }
+        }
+        return result;
+    }
+}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/tag/algorithm/ShardingAlgorithmBeanDefinitionTag.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-namespace-infra/src/main/java/org/apache/shardingsphere/spring/namespace/tag/ShardingSphereAlgorithmBeanDefinitionTag.java
similarity index 81%
copy from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/tag/algorithm/ShardingAlgorithmBeanDefinitionTag.java
copy to shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-namespace-infra/src/main/java/org/apache/shardingsphere/spring/namespace/tag/ShardingSphereAlgorithmBeanDefinitionTag.java
index 1a4321d..9bf1e84 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/main/java/org/apache/shardingsphere/sharding/spring/namespace/tag/algorithm/ShardingAlgorithmBeanDefinitionTag.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-namespace-infra/src/main/java/org/apache/shardingsphere/spring/namespace/tag/ShardingSphereAlgorithmBeanDefinitionTag.java
@@ -15,18 +15,16 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.sharding.spring.namespace.tag.algorithm;
+package org.apache.shardingsphere.spring.namespace.tag;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 
 /**
- * Sharding algorithm bean definition tag.
+ * ShardingSphere algorithm bean definition tag.
  */
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ShardingAlgorithmBeanDefinitionTag {
-    
-    public static final String ROOT_TAG = "sharding-algorithm";
+public final class ShardingSphereAlgorithmBeanDefinitionTag {
     
     public static final String TYPE_ATTRIBUTE = "type";