Spring Session table-name 属性不改变表名 [英] Spring Session table-name property does not change the table name

查看:69
本文介绍了Spring Session table-name 属性不改变表名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须能够重命名默认的 Spring Session 表并在 spring 会话文档.

I have to be able to rename the default Spring Session table and found the following configuration options in the spring session documentation.

spring.session.jdbc.schema=classpath:org/springframework/session/jdbc/schema-@@platform@@.sql # 用于初始化数据库模式的 SQL 文件的路径.spring.session.jdbc.table-name=SPRING_SESSION # 用于存储会话的数据库表名.

spring.session.jdbc.schema=classpath:org/springframework/session/jdbc/schema-@@platform@@.sql # Path to the SQL file to use to initialize the database schema. spring.session.jdbc.table-name=SPRING_SESSION # Name of database table used to store sessions.

这是我试图在 application.properties 中设置的内容:

Here is what I am trying to set in application.properties:

spring.session.store-type=jdbc
spring.session.jdbc.table-name: APP_SPR_SESSION
spring.session.jdbc.schema: src/main/resources/appSpringSession.sql

这里是appSpringSession.sql的内容,它是schema-oracle.sql

Here are the contents of appSpringSession.sql which is a modified/renamed version of schema-oracle.sql

CREATE TABLE app_app.APP_SPR_SESSION (
   PRIMARY_ID CHAR(36) NOT NULL,
   SESSION_ID CHAR(36) NOT NULL,
   CREATION_TIME NUMBER(19,0) NOT NULL,
   LAST_ACCESS_TIME NUMBER(19,0) NOT NULL,
   MAX_INACTIVE_INTERVAL NUMBER(10,0) NOT NULL,
   EXPIRY_TIME NUMBER(19,0) NOT NULL,
   PRINCIPAL_NAME VARCHAR2(100 CHAR),
   CONSTRAINT APP_SPR_SESSION_PK PRIMARY KEY (PRIMARY_ID)
);

CREATE UNIQUE INDEX APP_SPR_SESSION_IX1 ON APP_SPR_SESSION (SESSION_ID);
CREATE INDEX APP_SPR_SESSION_IX2 ON APP_SPR_SESSION (EXPIRY_TIME);
CREATE INDEX APP_SPR_SESSION_IX3 ON APP_SPR_SESSION (PRINCIPAL_NAME);

CREATE TABLE app_app.APP_SPR_SESSION_ATTRIBUTES (
    SESSION_PRIMARY_ID CHAR(36) NOT NULL,
    ATTRIBUTE_NAME VARCHAR2(200 CHAR) NOT NULL,
    ATTRIBUTE_BYTES BLOB NOT NULL,
    CONSTRAINT APP_SPR_SESSION_ATTRIBUTES_PK PRIMARY KEY 
    (SESSION_PRIMARY_ID, 
    ATTRIBUTE_NAME),
    CONSTRAINT APP_SPR_SESSION_ATTRIBUTES_FK FOREIGN KEY 
    (SESSION_PRIMARY_ID) 
    REFERENCES APP_SPR_SESSION(PRIMARY_ID) ON DELETE CASCADE
 );

我已使用上述 ddl 手动将表添加到 Oracle 数据库中,每次应用程序启动时,它仍在寻找 SPRING_SESSION 表.似乎指定这些选项无效.我从文档中读错了什么?

I have manually added the tables using the above ddl into the Oracle database and every time the app starts it's still looking for SPRING_SESSION table. Seems like specifying these options has no effect. What am I reading wrong here from the docs?

我还使用 Spring Session 2.0.2 Release 和 Spring Boot 2.0.1.RELEASE

Also I am using Spring Session 2.0.2 Release and Spring Boot 2.0.1.RELEASE

推荐答案

spring.session.* 对你不起作用的原因是你使用的是 @EnableJdbcHttpSession.这意味着您正在显式地配置 Spring Session,因此 Spring Boot 会通过其自动配置退出.

The reason spring.session.* do not work for you is because your are using @EnableJdbcHttpSession. That means that you are configuring Spring Session explicitly, so Spring Boot backs off with its auto-configuration.

您应该删除 @EnableJdbcHttpSession 并确保 Spring Boot 自动配置 Spring Session.此外,您还可以将 spring.session.store-type 排除在外,因为只要您只有 SessionRepository,Spring Boot 就应该能够推断出您正在使用哪个会话存储库实现code> 在类路径上的实现(即你只依赖于 spring-session-jdbc 而没有其他 Spring Session 模块).

You should remove @EnableJdbcHttpSession and ensure Spring Boot is auto-configuring Spring Session. Additionally, you could also leave spring.session.store-type out, since Spring Boot should be able to deduce which session repository implementation are you using as long as you have only only SessionRepository implementation on the classpath (i.e. you depend only on spring-session-jdbc and no other Spring Session modules).

这篇关于Spring Session table-name 属性不改变表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆