Spring Boot 1.5.2.RELEASE 数据库支持的会话

Spring Boot 1.5.2.RELEASE database backed sessions

我正在使用 Spring Boot 1.5 开发一个项目。2.RELEASE 并负责添加数据库支持的 HTTP 会话。

因此,我在 2.0.0.RELEASE 中轻松实现了这一点,应用程序启动并创建了表 spring_sessionspring_session_属性

以下是我添加到更高版本中的属性:

spring.session.store-type=jdbc
spring.session.jdbc.initialize-schema=ALWAYS

查看 spring-boot 1.5.2.RELEASE 它似乎使用 spring-session 1.3.0.RELEASE 作为托管版本所以我在这里找到了文档: https://docs.spring.io/spring-session/docs/1.3.0.RELEASE/reference/html5/guides/httpsession-jdbc.html

无论我尝试什么,我都会收到以下错误:

Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Tue Mar 20 14:02:06 GMT 2018 There was an unexpected error (type=Internal Server Error, status=500). PreparedStatementCallback; bad SQL grammar [SELECT S.SESSION_ID, S.CREATION_TIME, S.LAST_ACCESS_TIME, S.MAX_INACTIVE_INTERVAL, SA.ATTRIBUTE_NAME, SA.ATTRIBUTE_BYTES FROM SPRING_SESSION S LEFT OUTER JOIN SPRING_SESSION_ATTRIBUTES SA ON S.SESSION_ID = SA.SESSION_ID WHERE S.SESSION_ID = ?]; nested exception is org.postgresql.util.PSQLException: ERROR: relation "spring_session" does not exist Position: 127

这是我的 application.properties(我正在尝试让表出现在我的 PostgreSQL 数据库中)- 这些表应该会自动为我创建,对吗?

spring.datasource.url=jdbc:postgresql://localhost:5432/sandbox
spring.datasource.password=sandbox
spring.datasource.username=sandbox
spring.thymeleaf.cache=false
spring.template.cache=false
spring.session.store-type=jdbc
spring.session.jdbc.initializer.enabled=true

你加了这个试试 spring.session.jdbc.table-name=SPRING_SESSION

不幸的是,我无法让表自动创建,所以我在 spring-session jar 文件中挖掘了模式并手动创建了它们。好消息是会话现在已保存在我的数据库中!