电商后台项目需要访问的数据源

多数据源方法(读写分离)
方法1:jdk自带的dynamicdatasource
方法2:Mybatis 方式
方法3:dynamicdatasource框架
<dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.2.3</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId></dependency><dependency><groupId>com.baomidou</groupId><artifactId>dynamic-datasource-spring-boot-starter</artifactId><version>3.5.0</version></dependency>
spring:datasource:dynamic:primary: masterstrict: falsedatasource:master:url: jdbc:mysql://127.0.0.1:3306/datasource1?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF8&useSSL=falseusername: rootpassword: 123456initial-size: 1min-idle: 1max-active: 20test-on-borrow: truedriver-class-name: com.mysql.cj.jdbc.Driverslave_1:url: jdbc:mysql://127.0.0.1:3306/datasource2?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF8&useSSL=falseusername: rootpassword: rootinitial-size: 1min-idle: 1max-active: 20test-on-borrow: truedriver-class-name: com.mysql.cj.jdbc.Driver
@GetMapping(value = "select")@DS("slave_1")public List<Friend> select(){return friendService.list();}@GetMapping(value = "insert")@DS("master")public void in(){Friend friend = new Friend();friend.setName("loulan");friendService.save(friend);}