MrXionGe commented on issue #8306: URL: https://github.com/apache/shardingsphere/issues/8306#issuecomment-732530389
## pom.xml ``` <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.4.0</version> <relativePath/> </parent> <groupId>cn.mrxionge</groupId> <artifactId>replica-query</artifactId> <version>1.0-SNAPSHOT</version> <name>replica-query</name> <description>Demo project for Spring Boot</description> <properties> <java.version>11</java.version> </properties> <dependencies> <!-- spring --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.16</version> <scope>provided</scope> </dependency> <!-- DAO --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.22</version> </dependency> <dependency> <groupId>com.zaxxer</groupId> <artifactId>HikariCP</artifactId> <version>3.4.5</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.1</version> </dependency> <!-- sharding-jdbc --> <dependency> <groupId>org.apache.shardingsphere</groupId> <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId> <version>5.0.0-alpha</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> ``` ## application.properties ``` spring.shardingsphere.datasource.names=ds_0,ds_1 spring.shardingsphere.enabled=true spring.shardingsphere.datasource.common.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.common.driver-class-name=com.mysql.jdbc.Driver spring.shardingsphere.datasource.common.username=web_app spring.shardingsphere.datasource.common.password= 123456 spring.shardingsphere.datasource.ds_0.jdbc-url=jdbc:mysql://127.0.0.1:3306/db_master?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai spring.shardingsphere.datasource.ds_1.jdbc-url=jdbc:mysql://127.0.0.1:3306/db_read?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai spring.shardingsphere.rules.replica-query.load-balancers.round-robin.type=ROUND_ROBIN spring.shardingsphere.rules.replica-query.data-sources.ds.primary-data-source-name=ds_0 spring.shardingsphere.rules.replica-query.data-sources.ds.replica-data-source-names=ds_1 spring.shardingsphere.rules.replica-query.data-sources.ds.load-balancer-name=round-robin ``` ## ReplicaQueryApplication ``` package cn.mrxionge.replicaquery; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class ReplicaQueryApplication { public static void main(String[] args) { SpringApplication.run(ReplicaQueryApplication.class, args); } } ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
