簡體   English   中英

更改 Spring Boot 使用的數據庫模式

[英]Change database schema used by Spring Boot

如何指定 Spring Boot 使用的數據庫模式? 我正在使用默認休眠(=default)和postgres(但我希望有一個通用的解決方案)。 我知道如何指定 JDBC URL:

spring.datasource.url=jdbc:postgresql:db_name

但不幸的是,postgresql 不允許在 JDBC URL 中指定模式。 我知道有休眠屬性hibernate.default_schema ,所以我希望以下屬性之一可以工作:

hibernate.default_schema=schema
spring.hibernate.default_schema=schema
spring.jpa.hibernate.default_schema=raw_page

但不幸的是,他們似乎都沒有任何結果。

用於application.properties

spring.jpa.properties.hibernate.default_schema=your_scheme 

或用於application.yaml

spring:
  jpa:
    properties:
      hibernate.default_schema: your_scheme

從 Spring Boot 參考指南:

當創建本地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

這取決於必須使用哪個屬性來設置默認架構( 參考)的 DataSource 實現。 以 HikariDataSource 為例spring.jpa.properties.hibernate.default_schema被忽略,你必須設置

spring.datasource.hikari.schema=schema

此處查看 HikariCP 配置參數的完整列表。

spring:
  jpa:
    properties:
      hibernate:
        default_schema: your_schema_name

spring.jpa.properties.hibernate.default_schema=your_scheme

或者

春天:jpa:屬性:hibernate.default_schema:your_scheme

使用HikariDataSource例如 spring.jpa.properties.hibernate.default_schema 被忽略,你也必須設置

spring.datasource.hikari.schema=your_scheme

我遇到錯誤:無法從數據源 org.postgresql.util.PSQLException 獲取連接:錯誤:不支持的啟動參數:search_path

解決方案:application-k8s_dev.yml

網址:jdbc:postgresql://localhost:8080/your_database?search_path=your_scheme&stringtype=unspecified

春天:jpa:屬性:hibernate.default_schema:your_scheme

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM