【发布时间】:2019-11-09 18:14:49
【问题描述】:
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(“Run as” - “Spring Boot App”)上运行它时,它使用我的 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 会接管会话管理吗?这是怎么发生的?
【问题讨论】:
-
在这两种情况下您是否使用相同的弹簧型材?
-
是的。我只有一个个人资料
标签: spring-boot spring-mvc redis