Spring Boot JOOQ sql 未从 application.properties 中获取方言

Spring Boot JOOQ sql dialect not picked up from application.properties

背景:我在我的 nexus 存储库中托管 jooq 3.9.1 的试用版(专有的,例如 oracle db 兼容)——我的 pom 中与 jooq 相关的所有依赖项都指向那个。

我的 application.properties

中有这一行
jooq.sql-dialect=ORACLE

但是当我检查注入的 dslContext 时,方言设置为 "DEFAULT" 而不是 ORACLE 为 expected/desired.

我目前通过自动装配数据源而不是 dslcontext 然后设置 sql 方言(如下所示)来绕过它 - 但想知道为什么直接自动装配 dslcontext 不能按预期工作

@Autowired
private DataSourceConnectionProvider dataSource;



public static final SQLDialect sqlDialect = SQLDialect.ORACLE;

public DSLContext getDSL(){
    return DSL.using(dataSource, sqlDialect);
}

Spring Boot by default uses the org.jooq dependency,这是 jOOQ 开源版的 Maven groupId

<dependency>
    <groupId>org.jooq</groupId>
    <artifactId>jooq</artifactId>
</dependency>

然而,Oracle SQLDialect is contained only in the commercial distributions of jOOQ, which are available under different groupId (and not from Maven Central but from here (trial) and here (express, professional, enterprise edition)):

<groupId>org.jooq.pro</groupId>        <!-- for commercial editions -->
<groupId>org.jooq.pro-java-6</groupId> <!-- for commercial editions with Java 6 support -->
<groupId>org.jooq.trial</groupId>      <!-- for the free trial edition -->

这些发行版几乎完全二进制兼容,因此您应该能够简单地替换您自己的 pom.xml 中的 <groupId>,以便 Spring Boot 与 jOOQ 和 Oracle 一起工作。

Lukas 的评论 是正确的。

这是一个如何做和测试的例子:

里面application.properties

spring.jooq.sql-dialect = Postgres

并通过集成测试进行测试 ConfigIT:

@RunWith(SpringRunner.class)
@JdbcTest
@ImportAutoConfiguration(JooqAutoConfiguration.class)
public class ConfigIT {

    @Autowired
    private DSLContext dSLContext;

    @Test
    public void dialectShouldBePickedUp() {
        assertThat(dSLContext.configuration().dialect(), is(SQLDialect.POSTGRES));
    }
}

您将在 http://springbootbuch.de here: https://github.com/springbootbuch/database_examples

的存储库中找到工作和测试示例

重要的是选择正确的、区分大小写的名称。在我的例子中,它是Postgres,在你的例子中它应该是Oracle并且你必须使用正确的属性。遗憾的是,这些名称因不同的工具集而异。对于 jOOQ,您将在 org.jooq.SQLDialect

中找到常量