Spring 命名空间配置

简介

ShardingSphere-JDBC 提供官方的 Spring 命名空间配置,使开发者可以非常便捷的整合 ShardingSphere-JDBC 和 Spring 框架。

Spring 命名空间配置项

配置示例

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:shardingsphere="http://shardingsphere.apache.org/schema/shardingsphere/datasource"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://shardingsphere.apache.org/schema/shardingsphere/datasource
  7. http://shardingsphere.apache.org/schema/shardingsphere/datasource/datasource.xsd
  8. ">
  9. <bean id="ds0" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
  10. <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  11. <property name="url" value="jdbc:mysql://localhost:3306/ds0" />
  12. <property name="username" value="root" />
  13. <property name="password" value="" />
  14. </bean>
  15. <bean id="ds1" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
  16. <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  17. <property name="url" value="jdbc:mysql://localhost:3306/ds1" />
  18. <property name="username" value="root" />
  19. <property name="password" value="" />
  20. </bean>
  21. <!-- 配置规则,更多详细配置请参见具体的规则配置部分。 -->
  22. <!-- ... -->
  23. <shardingsphere:data-source id="shardingDataSource" data-source-names="ds0,ds1" rule-refs="..." >
  24. <props>
  25. <prop key="xxx.xxx">${xxx.xxx}</prop>
  26. </props>
  27. </shardingsphere:data-source>
  28. </beans>

配置项说明

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

<shardingsphere:data-source />

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