简体   繁体   English

如何使用 jooq 从同一 spring 引导服务中的两个数据源生成 pojos

[英]How to generate pojos using jooq from two data sources in the same spring boot service

I want to generate pojos using jooq from two datasources (Two separate MySQL database hosted on separate AWS RDS) in the same spring boot serivce.我想在同一个spring 引导服务中使用来自两个数据源的jooq (两个独立的 MySQL 数据库托管在不同的 AWS RDS 上)生成 pojo。 How can I do that?我怎样才能做到这一点?

I doubt if following can be used here:我怀疑是否可以在这里使用以下内容:

jooq {
    DBONE(sourceSets.main) {
        jdbc {
            driver = 'com.mysql.cj.jdbc.Driver'
            url = ...
            user = ...
            password = ...
        }
        generator {
            database {
                includes = '<DB_ONE>.*'
            }
            generate {
                relations = true
                records = true
                pojos = true...
            }
            target {
                packageName = 'com.abcd.jooq'
                directory = 'build/src/generated/java'
            }
        }
    }

    DBTWO(sourceSets.main) {
        jdbc {
            driver = 'com.mysql.cj.jdbc.Driver'
            url = ...
            user = ...
            password = ...
        }
        generator {
            database {
                includes = '<DB_TWO>.*'
            }
            generate {
                relations = true
                records = true
                pojos = true...
            }
            target {
                packageName = 'com.abcd.jooq'
                directory = 'build/src/generated/java'
            }
        }
    }
}

I could notice that only one config.xml could be found after build the spring boot application.我注意到在构建 spring 启动应用程序后只能找到一个 config.xml。 And pojos generated for only one datasource.并且仅为一个数据源生成 pojo。 Can any please suggest any to do the same?任何人都可以建议任何人做同样的事情吗?

You can't let two generation runs generate code into the same package.您不能让两代运行生成代码到同一个 package 中。 Every generation configuration owns its package and will remove everything that doesn't belong there.每一代配置都拥有其 package 并将删除不属于那里的所有内容。

You have two options:你有两个选择:

  • Use different target packages使用不同的目标包
  • Use some development code generation data source that allows you to access both databases from the same server, eg by using testcontainers ( example here ), or even the DDLDatabase使用一些开发代码生成数据源,允许您从同一服务器访问两个数据库,例如通过使用测试容器( 此处示例DDLDatabase ,甚至DDLDatabase

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM