数据库配置如下:
spring: datasource: dynamic: primary: ds1 #设置默认的数据源或者数据源组,默认值即为master strict: false #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源 datasource: ds1: url: jdbc:sap://192.168.0.220:30015 username: system1024 password: Gelisi2023 driver-class-name: com.sap.db.jdbc.Driver ds2: url: jdbc:mysql://156.75.217.201:3306/ellassay_erp username: root password: '!1023-uP1588opop7551=!' driver-class-name: com.mysql.cj.jdbc.Driver
对应service加上注解
@Service @DS("ds2") public class DepotSyncToErpService {
此时自动切换到ds2数据库
建议在mapper层设置