Logo
Spring 命名空间

简介 #

DBPlusEngine-Driver 提供官方的 Spring 命名空间,使开发者可以非常便捷的整合 DBPlusEngine-Driver 和 Spring。

使用步骤 #

引入 Maven 依赖 #

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

配置 Spring Bean #

配置项说明 #

命名空间:http://shardingsphere.apache.org/schema/shardingsphere/datasource/datasource-5.0.0.xsd

<shardingsphere:data-source />

名称类型说明
id属性Spring Bean Id
schema-name (?)属性JDBC 数据源别名
data-source-names标签数据源名称,多个数据源以逗号分隔
rule-refs标签规则名称,多个规则以逗号分隔
mode (?)标签运行模式配置
props (?)标签属性配置,详情请参见属性配置

配置示例 #

<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>

在 Spring 中使用 DBPlusEngine 数据源 #

使用方式同 Spring Boot Starter。