Spring Boot版本:2.1.5.RELEASE
我有一个简单的Spring Boot MVC应用程序,它使用Redis进行Spring会话存储。
spring:
session:
store-type: redis
redis:
flush-mode: on-save
namespace: spring:session
redis:
host: localhost
password:
port: 6379
database: 0
当我在STS(“运行方式”-“ Spring Boot应用程序”)上运行它时,它将使用Redis安装进行会话存储。我可以看到Redis上添加了键(键*)。
但是,当我在命令提示符下使用bootRun运行它时,与会话相关的所有内容似乎都可以正常工作,但是在Redis服务器上看不到任何键。似乎它甚至都没有连接到我的Redis服务器。我什至可以安全地关闭Redis,而不会影响任何事情。
我已确保两种运行模式之间的系统属性相同。有什么区别?在后一种情况下,它可以连接到哪里?
[编辑]
在org.springframework.session上启用TRACE之后,我在日志文件中注意到了什么-
在STS上运行时,我会看到这些日志条目(预期)-
2019-06-27 14:23:47.086 DEBUG No session found by id: Caching result for getSession(false) for this HttpServletRequest. | HP-20111108 | org.springframework.session.web.http.SessionRepositoryFilter.SESSION_LOGGER | nio-8080-exec-1
2019-06-27 14:23:47.087 DEBUG A new session was created. To help you troubleshoot where the session was created we provided a StackTrace (this is not an error). You can prevent this from appearing by disabling DEBUG logging for org.springframework.session.web.http.SessionRepositoryFilter.SESSION_LOGGER | HP-20111108 | org.springframework.session.web.http.SessionRepositoryFilter.SESSION_LOGGER | nio-8080-exec-1
java.lang.RuntimeException: For debugging purposes only (not an error)
at org.springframework.session.web.http.SessionRepositoryFilter$SessionRepositoryRequestWrapper.getSession(SessionRepositoryFilter.java:332) [spring-session-core-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.session.web.http.SessionRepositoryFilter$SessionRepositoryRequestWrapper.getSession(SessionRepositoryFilter.java:354) [spring-session-core-2.1.6.RELEASE.jar:2.1.6.RELEASE]
.....
2019-06-27 14:24:00.003 DEBUG Cleaning up sessions expiring at Thu Jun 27 14:24:00 CDT 2019 | HP-20111108 | org.springframework.session.data.redis.RedisSessionExpirationPolicy | pool-2-thread-1
使用bootRun运行时,这是我看到的唯一日志条目-
2019-06-27 14:27:05.936 WARN Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [382] milliseconds. | HP-20111108 | org.apache.catalina.util.SessionIdGeneratorBase | nio-8080-exec-1
使用bootRun运行时,Tomcat是否可以接管会话管理?怎么发生的?
答案 0 :(得分:0)
当!看来这是我的错。我在STS中的项目已关闭。这是一个Gradle项目,我对该项目进行了一些更改,但不知道我必须执行“刷新Gradle项目”。无论如何,它们现在处于同步状态,并且行为类似,但可悲的是,它们都表现出错误的方式(不使用Redis),但是我想那是一个单独的问题。