问题
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 # 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.
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
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
);
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?
Also I am using Spring Session 2.0.2 Release and Spring Boot 2.0.1.RELEASE
回答1:
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.
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).
来源:https://stackoverflow.com/questions/51751772/spring-session-table-name-property-does-not-change-the-table-name