Logo
Spring Namespace

Overview #

DBPlusEngine-Driver provides official Spring Namespace to make convenient for developers to integrate DBPlusEngine-Driver and Spring.

Usage #

Import Maven Dependency #

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-jdbc-core-spring-namespace</artifactId>
    <version>${shardingsphere.version}</version>
</dependency>

Configure Spring Bean #

Configuration Item Explanation #

Namespace: http://shardingsphere.apache.org/schema/shardingsphere/datasource/datasource-5.0.0.xsd

<shardingsphere:data-source />

NameTypeDescription
idAttributeSpring Bean Id
schema-name (?)AttributeJDBC data source alias
data-source-namesAttributeData source name, multiple data source names are separated by commas
rule-refsAttributeRule name, multiple rule names are separated by commas
mode (?)TagMode configuration
props (?)TagProperties configuration, Please refer to Properties Configuration for more details

Example #

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:shardingsphere="http://shardingsphere.apache.org/schema/shardingsphere/datasource"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
                           http://www.springframework.org/schema/beans/spring-beans.xsd 
                           http://shardingsphere.apache.org/schema/shardingsphere/datasource
                           http://shardingsphere.apache.org/schema/shardingsphere/datasource/datasource.xsd
                           ">
    <shardingsphere:data-source id="ds" schema-name="foo_schema" data-source-names="..." rule-refs="...">
        <shardingsphere:mode type="..." />
        <props>
            <prop key="xxx.xxx">${xxx.xxx}</prop>
        </props>
    </shardingsphere:data-source>
</beans>

Use DBPlusEngine Data Source in Spring #

Same with Spring Boot Starter.