diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index a4088d50..0e9dc8ca 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -492,13 +492,13 @@ services: - /docker/grafana/grafana.ini:/etc/grafana/grafana.ini - /docker/grafana:/var/lib/grafana network_mode: "host" + shardingproxy: - image: apache/shardingsphere-proxy + image: apache/shardingsphere-proxy:5.3.2 container_name: shardingsphere-proxy - restart: always command: server /data ports: - - 13307:3307 + - "3307:3307" volumes: - /docker/shardingproxy/conf:/opt/shardingsphere-proxy/conf - /docker/shardingproxy/ext-lib:/opt/shardingsphere-proxy/ext-lib diff --git a/ruoyi-example/ruoyi-demo/src/main/java/org/dromara/demo/controller/TestShardingController.java b/ruoyi-example/ruoyi-demo/src/main/java/org/dromara/demo/controller/TestShardingController.java index 5d34545e..498794d3 100644 --- a/ruoyi-example/ruoyi-demo/src/main/java/org/dromara/demo/controller/TestShardingController.java +++ b/ruoyi-example/ruoyi-demo/src/main/java/org/dromara/demo/controller/TestShardingController.java @@ -1,6 +1,5 @@ package org.dromara.demo.controller; -import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import lombok.RequiredArgsConstructor; @@ -11,8 +10,9 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.List; - +/** + * 使用方式 https://blog.csdn.net/zhaozhiqiang1981/article/details/129935075 + */ @RequiredArgsConstructor @RestController @RequestMapping("/sharding") diff --git a/ruoyi-example/ruoyi-demo/src/main/resources/application.yml b/ruoyi-example/ruoyi-demo/src/main/resources/application.yml index a4ae5537..d3c4f2c6 100644 --- a/ruoyi-example/ruoyi-demo/src/main/resources/application.yml +++ b/ruoyi-example/ruoyi-demo/src/main/resources/application.yml @@ -39,7 +39,7 @@ spring: # 设置默认的数据源或者数据源组,默认值即为 master primary: master datasource: -# 主库数据源 + # 主库数据源 master: type: ${spring.datasource.type} driver-class-name: com.mysql.cj.jdbc.Driver @@ -48,7 +48,8 @@ spring: password: ${datasource.system-master.password} sharding: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.0.60:3307/data-center_db?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true + # shardingproxy 服务的ip地址 + url: jdbc:mysql://127.0.0.1:3307/data-center_db?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true username: root password: root # oracle: