openEuler 尤拉、麒麟軟體加持,NestOS Beta 系統正式釋出
阿新 • • 發佈:2022-01-30
啟動類增加
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
pom.xml增加
<dependency> <groupId>com.baomidou</groupId> <artifactId>dynamic-datasource-spring-boot-starter</artifactId> <version>3.0.0</version></dependency>
application.yml
spring: datasource: dynamic: primary: db1 # 配置預設資料庫 datasource: db1: # 資料來源1配置 url: jdbc:mysql://ip1:port2/dbname1?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&serverTimezone=Asia/Shanghai username: jtiptv password: LtXtJc_iptv2018 driver-class-name: com.mysql.jdbc.Driver db2: # 資料來源2配置 url: jdbc:mysql://ip2:port2/dbname2?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&serverTimezone=Asia/Shanghai username: root password: root driver-class-name: com.mysql.jdbc.Driver durid: initial-size: 1 max-active: 20 min-idle: 1 max-wait: 60000
對應service或mapper增加註解
@DS("db1")