簡體   English   中英

Spring Session with JDBC - 如何指定會話表的架構

[英]Spring Session with JDBC - how do I specify the schema for the session tables

我正在使用帶有 Postgres 的 Spring Session 來存儲 Spring Boot 應用程序的用戶會話。 Spring Session 正在尋找公共模式中的 spring_session 和 spring_session_attributes 表。 有沒有辦法告訴 Spring Session 在 public 以外的模式中查找會話表? application.properties 中的 spring.jpa.properties.hibernate.default_schema 似乎對此沒有影響。

我設法在連接字符串/數據源URL指定的架構如下(也可作為一個答案描述要解決的問題在這里):

spring.datasource.url=jdbc:postgresql://localhost:9999/db_name?currentSchema=<schema_name>

仍然不確定為什么 application.properties 中的 spring.session.jdbc.schema 屬性對 spring 會話使用的架構沒有影響......

其實參數 spring.session.jdbc.schema 並不是指“數據庫模式”,而是 SQL 模式(定義存儲會話數據的數據結構的 SQL)。

不同數據庫的模式可在以下位置獲得:

https://github.com/spring-projects/spring-session/tree/master/spring-session-jdbc/src/main/resources/org/springframework/session/jdbc

您可以在application.properties設置 Spring Session 使用的表名,如下所示:

spring.session.jdbc.table-name = MY_SCHEMA.SPRING_SESSION

因此,Spring Session 發出的 SQL 查詢將針對您指定模式的表。 另見org.springframework.session.jdbc.JdbcOperationsSessionRepository

暫無
暫無

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

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