springboot + mybatis + sharding-jdbc + druid + mysql
gradle
dependencies { //Spring Boot compile('org.springframework.boot:spring-boot-starter-web') //Swagger2 //MyBatis compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1') //sharding jdbc compile('io.shardingjdbc:sharding-jdbc-spring-boot-starter:2.0.0.M2') //Druid compile 'com.alibaba:druid-spring-boot-starter:1.1.5' //MySQL runtime('mysql:mysql-connector-java') testCompile('org.springframework.boot:spring-boot-starter-test') }
application.properties
server.port=8081 sharding.jdbc.datasource.names=ds_master,ds_slave_0,ds_slave_1 sharding.jdbc.datasource.ds_master.type=com.alibaba.druid.pool.DruidDataSource sharding.jdbc.datasource.ds_master.driverClassName=com.mysql.jdbc.Driver sharding.jdbc.datasource.ds_master.url=jdbc:mysql://10.0.0.201:3306/web?useUnicode=true&characterEncoding=utf8 sharding.jdbc.datasource.ds_master.username=web sharding.jdbc.datasource.ds_master.password=web sharding.jdbc.datasource.ds_master.initial-size=1 sharding.jdbc.datasource.ds_master.min-idle=1 sharding.jdbc.datasource.ds_master.max-active=5 sharding.jdbc.datasource.ds_master.filter.stat.log-slow-sql=true sharding.jdbc.datasource.ds_master.filter.wall.enabled=true sharding.jdbc.datasource.ds_slave_0.type=com.alibaba.druid.pool.DruidDataSource sharding.jdbc.datasource.ds_slave_0.driverClassName=com.mysql.jdbc.Driver sharding.jdbc.datasource.ds_slave_0.url=jdbc:mysql://10.0.0.202:3306/web?useUnicode=true&characterEncoding=utf8 sharding.jdbc.datasource.ds_slave_0.username=web sharding.jdbc.datasource.ds_slave_0.password=web sharding.jdbc.datasource.ds_slave_0.initial-size=1 sharding.jdbc.datasource.ds_slave_0.min-idle=1 sharding.jdbc.datasource.ds_slave_0.max-active=5 sharding.jdbc.datasource.ds_slave_0.filter.stat.log-slow-sql=true sharding.jdbc.datasource.ds_slave_0.filter.wall.enabled=true sharding.jdbc.datasource.ds_slave_1.type=com.alibaba.druid.pool.DruidDataSource sharding.jdbc.datasource.ds_slave_1.driverClassName=com.mysql.jdbc.Driver sharding.jdbc.datasource.ds_slave_1.url=jdbc:mysql://10.0.0.203:3306/web?useUnicode=true&characterEncoding=utf8 sharding.jdbc.datasource.ds_slave_1.username=web sharding.jdbc.datasource.ds_slave_1.password=web sharding.jdbc.datasource.ds_slave_1.initial-size=1 sharding.jdbc.datasource.ds_slave_1.min-idle=1 sharding.jdbc.datasource.ds_slave_1.max-active=5 sharding.jdbc.datasource.ds_slave_1.filter.stat.log-slow-sql=true sharding.jdbc.datasource.ds_slave_1.filter.wall.enabled=true sharding.jdbc.config.masterslave.load-balance-algorithm-type=round_robin sharding.jdbc.config.masterslave.name=ds_ms sharding.jdbc.config.masterslave.master-data-source-name=ds_master sharding.jdbc.config.masterslave.slave-data-source-names=ds_slave_1,ds_slave_0
版权声明:本文为chenhaifeng2016原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。