【问题标题】:Spring Session with JDBC - how do I specify the schema for the session tablesSpring Session with JDBC - 如何为会话表指定模式
【发布时间】:2017-08-14 18:06:45
【问题描述】:

我正在使用带有 Postgres 的 Spring Session 来存储 Spring Boot 应用程序的用户会话。 Spring Session 正在公共模式中寻找 spring_session 和 spring_session_attributes 表。有没有办法告诉 Spring Session 在公共以外的模式中查找会话表? application.properties 中的 spring.jpa.properties.hibernate.default_schema 似乎对此没有影响。

【问题讨论】:

    标签: java spring session spring-boot


    【解决方案1】:

    我设法通过在连接字符串/数据源 URL 中指定架构来解决问题,如下所示(也如答案 here 中所述):

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

    仍然不确定为什么 application.properties 中的 spring.session.jdbc.schema 属性对 spring session 使用的架构没有影响...

    【讨论】:

      【解决方案2】:

      其实参数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

      【讨论】:

        【解决方案3】:

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

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

        因此,Spring Session 发出的 SQL 查询将针对您指定模式的表。另见org.springframework.session.jdbc.JdbcOperationsSessionRepository

        【讨论】:

          猜你喜欢
          • 2019-05-30
          • 1970-01-01
          • 2021-02-14
          • 1970-01-01
          • 2018-03-07
          • 1970-01-01
          • 2022-01-13
          • 1970-01-01
          • 2018-02-03
          相关资源
          最近更新 更多