Any data source configured as spring bean can be cooperated with spring namespace.

Example

In this example, the database driver is MySQL, and connection pool is HikariCP, which can be replaced with other database drivers and connection pools.

  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="ds1" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
  10. <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  11. <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/ds1" />
  12. <property name="username" value="root" />
  13. <property name="password" value="" />
  14. </bean>
  15. <bean id="ds2" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
  16. <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  17. <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/ds2" />
  18. <property name="username" value="root" />
  19. <property name="password" value="" />
  20. </bean>
  21. <shardingsphere:data-source id="ds" schema-name="foo_schema" data-source-names="ds1,ds2" rule-refs="..." />
  22. </beans>