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

jianglongtao 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 e6328cb989c Add spi-based-sharding-spring-namespace-mybatis-example 
for spi-based-sharding-algorithm-example (#19163)
e6328cb989c is described below

commit e6328cb989cfb789189227892cb892740095d2d6
Author: Runqi Zhao <[email protected]>
AuthorDate: Fri Jul 15 11:36:59 2022 +0800

    Add spi-based-sharding-spring-namespace-mybatis-example for 
spi-based-sharding-algorithm-example (#19163)
    
    * Add spi-based-sharding-spring-namespace-mybatis-example for 
spi-based-sharding-algorithm-example
    
    * fix ci
---
 .../spi-based-sharding-algorithm-example/pom.xml   |  1 +
 .../pom.xml                                        | 26 +++---
 .../SPIBasedShardingNamespaceMybatisExample.java   | 36 ++++++++
 ...DataSourceStandardShardingAlgorithmFixture.java | 61 ++++++++++++++
 ...dOrderItemStandardShardingAlgorithmFixture.java | 61 ++++++++++++++
 ...BasedOrderStandardShardingAlgorithmFixture.java | 61 ++++++++++++++
 .../application-sharding-databases-tables.xml      | 95 +++++++++++++++++++++
 .../META-INF/application-sharding-databases.xml    | 95 +++++++++++++++++++++
 .../META-INF/application-sharding-tables.xml       | 98 ++++++++++++++++++++++
 ...e.shardingsphere.sharding.spi.ShardingAlgorithm | 20 +++++
 .../src/main/resources/logback.xml                 | 34 ++++++++
 11 files changed, 578 insertions(+), 10 deletions(-)

diff --git 
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/pom.xml
 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/pom.xml
index 61b8f64f207..def28bfe10b 100644
--- 
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/pom.xml
+++ 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/pom.xml
@@ -33,6 +33,7 @@
         <module>spi-based-sharding-raw-jdbc-example</module>
         <module>spi-based-sharding-spring-boot-mybatis-example</module>
         <module>spi-based-sharding-spring-namespace-jpa-example</module>
+        <module>spi-based-sharding-spring-namespace-mybatis-example</module>
         <module>spi-based-sharding-spring-boot-jpa-example</module>
     </modules>
 </project>
diff --git 
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/pom.xml
 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/pom.xml
similarity index 68%
copy from 
examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/pom.xml
copy to 
examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/pom.xml
index 61b8f64f207..1a9b84d1560 100644
--- 
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/pom.xml
+++ 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/pom.xml
@@ -21,18 +21,24 @@
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
     <modelVersion>4.0.0</modelVersion>
     <parent>
+        <artifactId>spi-based-sharding-algorithm-example</artifactId>
         <groupId>org.apache.shardingsphere.example</groupId>
-        <artifactId>custom-sharding-algortihm-example</artifactId>
         <version>${revision}</version>
     </parent>
-    <artifactId>spi-based-sharding-algorithm-example</artifactId>
+    
<artifactId>spi-based-sharding-spring-namespace-mybatis-example</artifactId>
     <name>${project.artifactId}</name>
-    <packaging>pom</packaging>
-    
-    <modules>
-        <module>spi-based-sharding-raw-jdbc-example</module>
-        <module>spi-based-sharding-spring-boot-mybatis-example</module>
-        <module>spi-based-sharding-spring-namespace-jpa-example</module>
-        <module>spi-based-sharding-spring-boot-jpa-example</module>
-    </modules>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.shardingsphere.example</groupId>
+            <artifactId>example-spring-mybatis</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-jdbc-core-spring-namespace</artifactId>
+        </dependency>
+    </dependencies>
+
 </project>
diff --git 
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/spring/namespace/mybatis/SPIBasedShardingNamespaceMybatisExample.java
 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-
 [...]
new file mode 100644
index 00000000000..8d7206608ac
--- /dev/null
+++ 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/spring/namespace/mybatis/SPIBasedShardingNamespaceMybatisExample.java
@@ -0,0 +1,36 @@
+/*
+ * 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.example.extension.spibased.sharding.spring.namespace.mybatis;
+
+import org.apache.shardingsphere.example.core.api.ExampleExecuteTemplate;
+import org.apache.shardingsphere.example.core.api.service.ExampleService;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.sql.SQLException;
+
+public class SPIBasedShardingNamespaceMybatisExample {
+
+    private static final String CONFIG_FILE = 
"META-INF/application-sharding-databases.xml";
+
+    public static void main(final String[] args) throws SQLException {
+        try (ConfigurableApplicationContext applicationContext = new 
ClassPathXmlApplicationContext(CONFIG_FILE)) {
+            
ExampleExecuteTemplate.run(applicationContext.getBean(ExampleService.class));
+        }
+    }
+}
diff --git 
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/spring/namespace/mybatis/fixture/SPIBasedDataSourceStandardShardingAlgorithmFixture.java
 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/
 [...]
new file mode 100644
index 00000000000..2abe69969f8
--- /dev/null
+++ 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/spring/namespace/mybatis/fixture/SPIBasedDataSourceStandardShardingAlgorithmFixture.java
@@ -0,0 +1,61 @@
+/*
+ * 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.example.extension.spibased.sharding.spring.namespace.mybatis.fixture;
+
+import lombok.Getter;
+import 
org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
+import 
org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
+import 
org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;
+
+import java.util.Collection;
+import java.util.Properties;
+
+@Getter
+public final class SPIBasedDataSourceStandardShardingAlgorithmFixture 
implements StandardShardingAlgorithm<Integer> {
+    
+    private Properties props;
+    
+    @Override
+    public void init(final Properties props) {
+        this.props = props;
+    }
+    
+    @Override
+    public String doSharding(final Collection<String> dataSourceNames, final 
PreciseShardingValue<Integer> shardingValue) {
+        for (String each : dataSourceNames) {
+            if (each.endsWith(shardingSuffix(shardingValue.getValue()))) {
+                return each;
+            }
+        }
+        return null;
+    }
+    
+    private String shardingSuffix(final Integer shardingValue) {
+        return "-" + (shardingValue % 2);
+    }
+    
+    @Override
+    public Collection<String> doSharding(final Collection<String> 
availableTargetNames, final RangeShardingValue<Integer> shardingValue) {
+        return availableTargetNames;
+    }
+    
+    @Override
+    public String getType() {
+        return "DATASOURCE_SPI_BASED";
+    }
+}
diff --git 
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/spring/namespace/mybatis/fixture/SPIBasedOrderItemStandardShardingAlgorithmFixture.java
 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/s
 [...]
new file mode 100644
index 00000000000..2e8e881eb09
--- /dev/null
+++ 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/spring/namespace/mybatis/fixture/SPIBasedOrderItemStandardShardingAlgorithmFixture.java
@@ -0,0 +1,61 @@
+/*
+ * 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.example.extension.spibased.sharding.spring.namespace.mybatis.fixture;
+
+import lombok.Getter;
+import 
org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
+import 
org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
+import 
org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;
+
+import java.util.Collection;
+import java.util.Properties;
+
+@Getter
+public final class SPIBasedOrderItemStandardShardingAlgorithmFixture 
implements StandardShardingAlgorithm<Long> {
+    
+    private Properties props;
+    
+    @Override
+    public void init(final Properties props) {
+        this.props = props;
+    }
+    
+    @Override
+    public String doSharding(final Collection<String> availableTargetNames, 
final PreciseShardingValue<Long> shardingValue) {
+        for (String each : availableTargetNames) {
+            if (each.endsWith(shardingSuffix(shardingValue.getValue()))) {
+                return each;
+            }
+        }
+        return null;
+    }
+    
+    private String shardingSuffix(final Long shardingValue) {
+        return "_" + (shardingValue % 2);
+    }
+    
+    @Override
+    public Collection<String> doSharding(final Collection<String> 
availableTargetNames, final RangeShardingValue<Long> shardingValue) {
+        return availableTargetNames;
+    }
+    
+    @Override
+    public String getType() {
+        return "T_ORDER_ITEM_SPI_BASED";
+    }
+}
diff --git 
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/spring/namespace/mybatis/fixture/SPIBasedOrderStandardShardingAlgorithmFixture.java
 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-b
 [...]
new file mode 100644
index 00000000000..48dd5f5a830
--- /dev/null
+++ 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/spring/namespace/mybatis/fixture/SPIBasedOrderStandardShardingAlgorithmFixture.java
@@ -0,0 +1,61 @@
+/*
+ * 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.example.extension.spibased.sharding.spring.namespace.mybatis.fixture;
+
+import lombok.Getter;
+import 
org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
+import 
org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
+import 
org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;
+
+import java.util.Collection;
+import java.util.Properties;
+
+@Getter
+public final class SPIBasedOrderStandardShardingAlgorithmFixture implements 
StandardShardingAlgorithm<Long> {
+    
+    private Properties props;
+    
+    @Override
+    public void init(final Properties props) {
+        this.props = props;
+    }
+    
+    @Override
+    public String doSharding(final Collection<String> availableTargetNames, 
final PreciseShardingValue<Long> shardingValue) {
+        for (String each : availableTargetNames) {
+            if (each.endsWith(shardingSuffix(shardingValue.getValue()))) {
+                return each;
+            }
+        }
+        return null;
+    }
+    
+    private String shardingSuffix(final Long shardingValue) {
+        return "_" + (shardingValue % 2);
+    }
+    
+    @Override
+    public Collection<String> doSharding(final Collection<String> 
availableTargetNames, final RangeShardingValue<Long> shardingValue) {
+        return availableTargetNames;
+    }
+    
+    @Override
+    public String getType() {
+        return "T_ORDER_SPI_BASED";
+    }
+}
diff --git 
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/resources/META-INF/application-sharding-databases-tables.xml
 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/ma
 [...]
new file mode 100644
index 00000000000..57d90b9ed59
--- /dev/null
+++ 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/resources/META-INF/application-sharding-databases-tables.xml
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns:context="http://www.springframework.org/schema/context";
+       xmlns:tx="http://www.springframework.org/schema/tx";
+       
xmlns:shardingsphere="http://shardingsphere.apache.org/schema/shardingsphere/datasource";
+       
xmlns:sharding="http://shardingsphere.apache.org/schema/shardingsphere/sharding";
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+                           
http://www.springframework.org/schema/beans/spring-beans.xsd
+                           http://www.springframework.org/schema/tx
+                           
http://www.springframework.org/schema/tx/spring-tx.xsd
+                           http://www.springframework.org/schema/context
+                           
http://www.springframework.org/schema/context/spring-context.xsd
+                           
http://shardingsphere.apache.org/schema/shardingsphere/datasource
+                           
http://shardingsphere.apache.org/schema/shardingsphere/datasource/datasource.xsd
+                           
http://shardingsphere.apache.org/schema/shardingsphere/sharding
+                           
http://shardingsphere.apache.org/schema/shardingsphere/sharding/sharding.xsd
+                           ">
+    <context:component-scan 
base-package="org.apache.shardingsphere.example.core.mybatis" />
+
+    <bean id="demo_ds_0" class="com.zaxxer.hikari.HikariDataSource" 
destroy-method="close">
+        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
+        <property name="jdbcUrl" 
value="jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&amp;useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
+        <property name="username" value="root"/>
+        <property name="password" value=""/>
+    </bean>
+
+    <bean id="demo_ds_1" class="com.zaxxer.hikari.HikariDataSource" 
destroy-method="close">
+        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
+        <property name="jdbcUrl" 
value="jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&amp;useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
+        <property name="username" value="root"/>
+        <property name="password" value=""/>
+    </bean>
+
+    <sharding:standard-strategy id="databaseStrategy" 
sharding-column="user_id" algorithm-ref="inlineStrategyShardingAlgorithm" />
+
+    <sharding:sharding-algorithm id="inlineStrategyShardingAlgorithm" 
type="INLINE">
+        <props>
+            <prop key="algorithm-expression">demo_ds_${user_id % 2}</prop>
+        </props>
+    </sharding:sharding-algorithm>
+
+    <sharding:key-generate-algorithm id="snowflakeAlgorithm" type="SNOWFLAKE">
+    </sharding:key-generate-algorithm>
+
+    <sharding:key-generate-strategy id="orderKeyGenerator" column="order_id" 
algorithm-ref="snowflakeAlgorithm" />
+    <sharding:key-generate-strategy id="itemKeyGenerator" 
column="order_item_id" algorithm-ref="snowflakeAlgorithm" />
+
+    <sharding:rule id="shardingRule">
+        <sharding:table-rules>
+            <sharding:table-rule logic-table="t_order" 
database-strategy-ref="databaseStrategy" 
key-generate-strategy-ref="orderKeyGenerator" />
+            <sharding:table-rule logic-table="t_order_item" 
database-strategy-ref="databaseStrategy" 
key-generate-strategy-ref="itemKeyGenerator" />
+        </sharding:table-rules>
+        <sharding:binding-table-rules>
+            <sharding:binding-table-rule logic-tables="t_order,t_order_item"/>
+        </sharding:binding-table-rules>
+        <sharding:broadcast-table-rules>
+            <sharding:broadcast-table-rule table="t_address"/>
+        </sharding:broadcast-table-rules>
+    </sharding:rule>
+
+    <shardingsphere:data-source id="shardingDataSource" 
database-name="sharding-databases" data-source-names="demo_ds_0, demo_ds_1" 
rule-refs="shardingRule" />
+
+    <bean id="transactionManager" 
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
+        <property name="dataSource" ref="shardingDataSource" />
+    </bean>
+    <tx:annotation-driven />
+
+    <bean id="sqlSessionFactory" 
class="org.mybatis.spring.SqlSessionFactoryBean">
+        <property name="dataSource" ref="shardingDataSource"/>
+        <property name="mapperLocations" 
value="classpath*:META-INF/mappers/*.xml"/>
+    </bean>
+
+    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
+        <property name="basePackage" 
value="org.apache.shardingsphere.example.core.mybatis.repository"/>
+        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
+    </bean>
+</beans>
diff --git 
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/resources/META-INF/application-sharding-databases.xml
 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/reso
 [...]
new file mode 100644
index 00000000000..57d90b9ed59
--- /dev/null
+++ 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/resources/META-INF/application-sharding-databases.xml
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns:context="http://www.springframework.org/schema/context";
+       xmlns:tx="http://www.springframework.org/schema/tx";
+       
xmlns:shardingsphere="http://shardingsphere.apache.org/schema/shardingsphere/datasource";
+       
xmlns:sharding="http://shardingsphere.apache.org/schema/shardingsphere/sharding";
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+                           
http://www.springframework.org/schema/beans/spring-beans.xsd
+                           http://www.springframework.org/schema/tx
+                           
http://www.springframework.org/schema/tx/spring-tx.xsd
+                           http://www.springframework.org/schema/context
+                           
http://www.springframework.org/schema/context/spring-context.xsd
+                           
http://shardingsphere.apache.org/schema/shardingsphere/datasource
+                           
http://shardingsphere.apache.org/schema/shardingsphere/datasource/datasource.xsd
+                           
http://shardingsphere.apache.org/schema/shardingsphere/sharding
+                           
http://shardingsphere.apache.org/schema/shardingsphere/sharding/sharding.xsd
+                           ">
+    <context:component-scan 
base-package="org.apache.shardingsphere.example.core.mybatis" />
+
+    <bean id="demo_ds_0" class="com.zaxxer.hikari.HikariDataSource" 
destroy-method="close">
+        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
+        <property name="jdbcUrl" 
value="jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&amp;useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
+        <property name="username" value="root"/>
+        <property name="password" value=""/>
+    </bean>
+
+    <bean id="demo_ds_1" class="com.zaxxer.hikari.HikariDataSource" 
destroy-method="close">
+        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
+        <property name="jdbcUrl" 
value="jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&amp;useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
+        <property name="username" value="root"/>
+        <property name="password" value=""/>
+    </bean>
+
+    <sharding:standard-strategy id="databaseStrategy" 
sharding-column="user_id" algorithm-ref="inlineStrategyShardingAlgorithm" />
+
+    <sharding:sharding-algorithm id="inlineStrategyShardingAlgorithm" 
type="INLINE">
+        <props>
+            <prop key="algorithm-expression">demo_ds_${user_id % 2}</prop>
+        </props>
+    </sharding:sharding-algorithm>
+
+    <sharding:key-generate-algorithm id="snowflakeAlgorithm" type="SNOWFLAKE">
+    </sharding:key-generate-algorithm>
+
+    <sharding:key-generate-strategy id="orderKeyGenerator" column="order_id" 
algorithm-ref="snowflakeAlgorithm" />
+    <sharding:key-generate-strategy id="itemKeyGenerator" 
column="order_item_id" algorithm-ref="snowflakeAlgorithm" />
+
+    <sharding:rule id="shardingRule">
+        <sharding:table-rules>
+            <sharding:table-rule logic-table="t_order" 
database-strategy-ref="databaseStrategy" 
key-generate-strategy-ref="orderKeyGenerator" />
+            <sharding:table-rule logic-table="t_order_item" 
database-strategy-ref="databaseStrategy" 
key-generate-strategy-ref="itemKeyGenerator" />
+        </sharding:table-rules>
+        <sharding:binding-table-rules>
+            <sharding:binding-table-rule logic-tables="t_order,t_order_item"/>
+        </sharding:binding-table-rules>
+        <sharding:broadcast-table-rules>
+            <sharding:broadcast-table-rule table="t_address"/>
+        </sharding:broadcast-table-rules>
+    </sharding:rule>
+
+    <shardingsphere:data-source id="shardingDataSource" 
database-name="sharding-databases" data-source-names="demo_ds_0, demo_ds_1" 
rule-refs="shardingRule" />
+
+    <bean id="transactionManager" 
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
+        <property name="dataSource" ref="shardingDataSource" />
+    </bean>
+    <tx:annotation-driven />
+
+    <bean id="sqlSessionFactory" 
class="org.mybatis.spring.SqlSessionFactoryBean">
+        <property name="dataSource" ref="shardingDataSource"/>
+        <property name="mapperLocations" 
value="classpath*:META-INF/mappers/*.xml"/>
+    </bean>
+
+    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
+        <property name="basePackage" 
value="org.apache.shardingsphere.example.core.mybatis.repository"/>
+        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
+    </bean>
+</beans>
diff --git 
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/resources/META-INF/application-sharding-tables.xml
 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/resourc
 [...]
new file mode 100644
index 00000000000..6d56c27685a
--- /dev/null
+++ 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/resources/META-INF/application-sharding-tables.xml
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns:context="http://www.springframework.org/schema/context";
+       xmlns:tx="http://www.springframework.org/schema/tx";
+       
xmlns:shardingsphere="http://shardingsphere.apache.org/schema/shardingsphere/datasource";
+       
xmlns:sharding="http://shardingsphere.apache.org/schema/shardingsphere/sharding";
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+                           
http://www.springframework.org/schema/beans/spring-beans.xsd
+                           http://www.springframework.org/schema/tx
+                           
http://www.springframework.org/schema/tx/spring-tx.xsd
+                           http://www.springframework.org/schema/context
+                           
http://www.springframework.org/schema/context/spring-context.xsd
+                           
http://shardingsphere.apache.org/schema/shardingsphere/datasource
+                           
http://shardingsphere.apache.org/schema/shardingsphere/datasource/datasource.xsd
+                           
http://shardingsphere.apache.org/schema/shardingsphere/sharding
+                           
http://shardingsphere.apache.org/schema/shardingsphere/sharding/sharding.xsd
+                           ">
+    <context:component-scan 
base-package="org.apache.shardingsphere.example.core.mybatis" />
+
+    <bean id="demo_ds" class="com.zaxxer.hikari.HikariDataSource" 
destroy-method="close">
+        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
+        <property name="jdbcUrl" 
value="jdbc:mysql://localhost:3306/demo_ds?serverTimezone=UTC&amp;useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
+        <property name="username" value="root"/>
+        <property name="password" value=""/>
+    </bean>
+
+    <sharding:standard-strategy id="orderTableStrategy" 
sharding-column="order_id" algorithm-ref="inlineOrderTableStrategyAlgorithm" />
+    <sharding:standard-strategy id="orderItemTableStrategy" 
sharding-column="order_id" 
algorithm-ref="inlineOrderItemTableStrategyAlgorithm" />
+
+    <sharding:sharding-algorithm id="inlineOrderTableStrategyAlgorithm" 
type="INLINE">
+        <props>
+            <prop key="algorithm-expression">t_order_${order_id % 2}</prop>
+        </props>
+    </sharding:sharding-algorithm>
+    <sharding:sharding-algorithm id="inlineOrderItemTableStrategyAlgorithm" 
type="INLINE">
+        <props>
+            <prop key="algorithm-expression">t_order_item_${order_id % 
2}</prop>
+        </props>
+    </sharding:sharding-algorithm>
+
+    <sharding:key-generate-algorithm id="snowflakeAlgorithm" type="SNOWFLAKE">
+    </sharding:key-generate-algorithm>
+
+    <sharding:key-generate-strategy id="orderKeyGenerator" column="order_id" 
algorithm-ref="snowflakeAlgorithm" />
+    <sharding:key-generate-strategy id="itemKeyGenerator" 
column="order_item_id" algorithm-ref="snowflakeAlgorithm" />
+
+    <sharding:rule id="shardingRule">
+        <sharding:table-rules>
+            <sharding:table-rule logic-table="t_order" 
actual-data-nodes="demo_ds.t_order_${0..1}" 
table-strategy-ref="orderTableStrategy" 
key-generate-strategy-ref="orderKeyGenerator" />
+            <sharding:table-rule logic-table="t_order_item" 
actual-data-nodes="demo_ds.t_order_item_${0..1}" 
table-strategy-ref="orderItemTableStrategy" 
key-generate-strategy-ref="itemKeyGenerator" />
+        </sharding:table-rules>
+        <sharding:binding-table-rules>
+            <sharding:binding-table-rule logic-tables="t_order,t_order_item"/>
+        </sharding:binding-table-rules>
+        <sharding:broadcast-table-rules>
+            <sharding:broadcast-table-rule table="t_address"/>
+        </sharding:broadcast-table-rules>
+    </sharding:rule>
+
+    <shardingsphere:data-source id="shardingDataSource" 
data-source-names="demo_ds" rule-refs="shardingRule">
+        <props>
+            <prop key="sql-show">false</prop>
+        </props>
+    </shardingsphere:data-source>
+
+    <bean id="transactionManager" 
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
+        <property name="dataSource" ref="shardingDataSource" />
+    </bean>
+    <tx:annotation-driven />
+
+    <bean id="sqlSessionFactory" 
class="org.mybatis.spring.SqlSessionFactoryBean">
+        <property name="dataSource" ref="shardingDataSource"/>
+        <property name="mapperLocations" 
value="classpath*:META-INF/mappers/*.xml"/>
+    </bean>
+
+    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
+        <property name="basePackage" 
value="org.apache.shardingsphere.example.core.mybatis.repository"/>
+        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
+    </bean>
+</beans>
diff --git 
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAlgorithm
 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespac
 [...]
new file mode 100644
index 00000000000..f7eaa033208
--- /dev/null
+++ 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAlgorithm
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.example.extension.spibased.sharding.spring.namespace.mybatis.fixture.SPIBasedOrderStandardShardingAlgorithmFixture
+org.apache.shardingsphere.example.extension.spibased.sharding.spring.namespace.mybatis.fixture.SPIBasedOrderItemStandardShardingAlgorithmFixture
+org.apache.shardingsphere.example.extension.spibased.sharding.spring.namespace.mybatis.fixture.SPIBasedDataSourceStandardShardingAlgorithmFixture
diff --git 
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/resources/logback.xml
 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/resources/logback.xml
new file mode 100644
index 00000000000..317fc4fd2a5
--- /dev/null
+++ 
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-mybatis-example/src/main/resources/logback.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<configuration>
+    <property name="log.context.name" 
value="spi-based-sharding-spring-namespace-mybatis-example" />
+    <property name="log.charset" value="UTF-8" />
+    <property name="log.pattern" value="[%-5level] %date --%thread-- [%logger] 
%msg %n" />
+    <contextName>${log.context.name}</contextName>
+
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder charset="${log.charset}">
+            <pattern>${log.pattern}</pattern>
+        </encoder>
+    </appender>
+    <root>
+        <level value="INFO" />
+        <appender-ref ref="STDOUT" />
+    </root>
+</configuration>

Reply via email to