首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java多数据Jdbc与R2dbc问题

Java多数据Jdbc与R2dbc问题
EN

Stack Overflow用户
提问于 2021-03-18 05:52:45
回答 1查看 632关注 0票数 1

我写了一个项目,并在那里使用了r2dbc和jdbc。现在数据库出现了一个问题。我怎么才能把他们分开?信息来了,但出了差错。

Operator called default onErrorDropped

Application.yml

代码语言:javascript
复制
   spring:
     liquibase:
       enabled: true
       url: jdbc:postgresql://localhost:5432/liquebase
       user: postgres
       password: 12345
       change-log: classpath:db/liquibase/db.changelog-master-main.yml
     datasource:
       driver-class-name: org.postgresql.Driver
       hikari:
       minimum-idle: 5
     r2dbc:
       url: r2dbc:postgresql://127.0.0.1:5432/liquebase
       username: postgres
       password: 12345
       pool:
         initial-size: 100
         max-size: 500
         max-idle-time: 30m
        validation-query: SELECT 1


  server:
    port: 8085
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-18 07:48:25

据我所知,您只能使用一个数据源。但是您可以在配置application.yml上配置两者并在它们之间切换。就像这样:

代码语言:javascript
复制
spring:
  profiles:
    active: dev00
---
spring:
  config:
    activate:
      on-profile: dev00
    liquibase:
      enabled: true
      url: jdbc:postgresql://localhost:5432/liquebase
      user: postgres
      password: 12345
      change-log: classpath:db/liquibase/db.changelog-master-main.yml
    datasource:
      driver-class-name: org.postgresql.Driver
      hikari:
      minimum-idle: 5
    server:
      port: 8085
---
spring:
  config:
    activate:
      on-profile: dev01
    r2dbc:
      url: r2dbc:postgresql://127.0.0.1:5432/liquebase
      username: postgres
      password: 12345
      pool:
        initial-size: 100
        max-size: 500
        max-idle-time: 30m
        validation-query: SELECT 1
    server:
      port: 8085

然后通过配置spring.profiles.active: dev00spring.profiles.active: dev01来决定使用哪一个。这个样本工程为您提供了一个很好的源代码。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66685475

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档