Search code examples
spring-bootspring-webfluxspring-jdbcspring-data-r2dbc

Java multiple data Jdbc and R2dbc problem


I wrote a project and I used r2dbc and jdbc there. Now there is a problem with the database. How can I separate them? The information comes but gives an error

Operator called default onErrorDropped

Application.yml

   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

Solution

  • As far as I know, you can use only one data source. But you can configure both and switch between them on the configuration application.yml. Something like this:

    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
    

    Then you decide which one to use by configuring spring.profiles.active: dev00 or spring.profiles.active: dev01. This sample project gives you a good source code.