Spring 引导不会加载用户定义的方言

Spring Boot won't load user-defined Dialect

我有一个应用程序使用自定义方言 Spring Boot JPA Hibernate。

自定义方言如下:

public class JsonPostgreSQL94Dialect extends PostgreSQL94Dialect {
   public JsonPostgreSQL94Dialect() {
      this.registerColumnType(Types.JAVA_OBJECT, "jsonb");
   }
}

此方言扩展了 PostgreSQL 方言并添加了对 jsonb 数据类型的支持。

现在,当我使用 Spring 引导启动我的应用程序时,在某些环境中它不会加载适当的方言。我尝试通过以下方式定义方言:

在application.properties中:

spring.jpa.properties.hibernate.dialect=org.test.util.JsonPostgreSQL94Dialect
spring.jpa.database-platform=org.test.util.JsonPostgreSQL94Dialect

此外,我可以在 hibernate.properties 中定义它:

hibernate.dialect=org.test.util.JsonPostgreSQL94Dialect

这是 Spring 我的应用程序在 Cloud Foundry 中使用 Java Buildpack 启动的引导日志:

   2017-11-13T18:03:54.79+0000 [APP/PROC/WEB/1] OUT 2017-11-13 18:03:54.792  INFO 19 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect

启动将无法识别我定义的方言。它默认为普通的 PostgreSQL 方言,这导致我的应用程序在无法识别的数据类型上失败。

Spring Boot 中有什么东西覆盖了我对方言的定义吗?有没有更恰当的方言定义方式?

问题是当项目部署到我们的 Cloud Foundry 环境时 Spring Auto-Reconfiguration 开始了。 Auto-Reconfiguration Bean 处于活动状态并负责更改我的应用程序的方言。这是因为我的数据库 (PostgreSQL) 的 VCAP 服务被 bean 检测到,然后被自动配置。

我的解决方案是通过将以下环境变量添加到我的应用程序清单来关闭自动重新配置 Bean:

JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{enabled: false}'

禁用自动重新配置后,我的方言不再被 Spring 覆盖。