Java 更改 Spring Boot 使用的数据库架构
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24278659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change database schema used by Spring Boot
提问by Paperback Writer
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 Boot 使用的数据库架构?我正在使用默认的休眠(=默认)和 postgres(但我希望有一个通用的解决方案)。我知道如何指定 JDBC URL:
spring.datasource.url=jdbc:postgresql:db_name
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:
但不幸的是 postgresql 不允许在 JDBC URL 中指定模式。我知道有 hibernate 属性hibernate.default_schema
,所以我希望以下属性之一可以工作:
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.
但不幸的是,他们似乎都没有任何结果。
采纳答案by M. Deinum
Use spring.jpa.properties.hibernate.default_schema=schema
.
使用spring.jpa.properties.hibernate.default_schema=schema
.
From the Spring Boot reference guide:
从 Spring Boot 参考指南:
all properties in spring.jpa.properties.* are passed through as normal JPA properties (with the prefix stripped) when the local EntityManagerFactory is created
当创建本地 EntityManagerFactory 时, spring.jpa.properties.* 中的所有属性都作为普通的 JPA 属性传递(去掉前缀)
See 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
有关可用属性的完整列表,请参阅http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-configure-jpa-properties
回答by vboerchers
It depends on the DataSource implementation which property has to be used to set the default schema (reference). With HikariDataSource for example spring.jpa.properties.hibernate.default_schema
is ignored and you have to set
这取决于必须使用哪个属性来设置默认架构(参考)的 DataSource 实现。例如 HikariDataSourcespring.jpa.properties.hibernate.default_schema
被忽略,你必须设置
spring.datasource.hikari.schema=schema
See the complete list of HikariCP configuration parameters here.
在此处查看 HikariCP 配置参数的完整列表。