问题描述
如何指定 Spring Boot 使用的数据库架构?我正在使用默认的休眠(=默认)和 postgres(但我希望有一个通用的解决方案).我知道如何指定 JDBC URL:
How do I specify database schema used by Spring Boot? I am using default hibernate (=default) and postgres (but i hoping for a generic solution). I know how to specify JDBC URL:
spring.datasource.url=jdbc:postgresql:db_name
但不幸的是 postgresql 不允许在 JDBC URL 中指定模式.我知道有休眠属性 hibernate.default_schema
,所以我希望以下属性之一可以工作:
But unfortunately postgresql does not allow to specify schema in JDBC URL. I know that there is hibernate property hibernate.default_schema
, so I was hoping that one of the following properties will work:
hibernate.default_schema=schema
spring.hibernate.default_schema=schema
spring.jpa.hibernate.default_schema=raw_page
但不幸的是,他们似乎都没有任何结果.
But unfortunately neither of them seems to have any result.
推荐答案
用于application.properties
:
spring.jpa.properties.hibernate.default_schema=your_scheme
application.yaml
的或:
spring:
jpa:
properties:
hibernate.default_schema: your_scheme
来自 Spring Boot 参考指南:
From the Spring Boot reference guide:
在创建本地 EntityManagerFactory
时,spring.jpa.properties.*
中的所有属性都作为普通的 JPA 属性(去掉前缀)传递
参见 http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-configure-jpa-properties
有关可用属性的完整列表,请参阅 http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-configure-jpa-properties
For a full list of available properties see http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-configure-jpa-properties
这篇关于更改 Spring Boot 使用的数据库架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!