【问题标题】:How to set hibernate.format_sql in spring-boot?如何在 spring-boot 中设置 hibernate.format_sql?
【发布时间】:2014-11-01 10:40:27
【问题描述】:

我正在使用spring-boot 自动配置进行数据库注入,并定义了属性:

spring.jpa.database=POSTGRESQL
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update

但是如何设置hibernate.format_sql=true? spring boot 不支持吗?

【问题讨论】:

    标签: java spring spring-boot spring-data-jpa


    【解决方案1】:

    Spring Boot 将允许您使用以下方法设置任何可用的休眠属性:

    spring.jpa.properties.*

    所以spring.jpa.properties.hibernate.format_sql=true 也可以。

    查看this 部分文档

    【讨论】:

      【解决方案2】:

      如果你使用yml格式声明Spring Boot属性,可以使用:

      spring:
        datasource:
        jpa:
          properties:
            hibernate.format_sql: true
      

      【讨论】:

        【解决方案3】:
        jpa:
          hibernate:
            ddl-auto: update
          show-sql: true
          properties:
            hibernate.format_sql: true
        

        【讨论】:

        • 像魅力一样工作
        【解决方案4】:

        这个很实用

        spring.jpa.hibernate.format_sql=true
        

        【讨论】:

        【解决方案5】:

        您可以使用:spring.jpa.properties.hibernate.format_sql=true

        除了documentation,我确实按照here 的示例来配置我的应用程序。您可以找到其中使用的属性示例。

        【讨论】:

          猜你喜欢
          • 2016-05-03
          • 2019-05-12
          • 1970-01-01
          • 1970-01-01
          • 2017-01-23
          • 2017-07-29
          • 2019-02-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多