spring-boot - "STS - Run As - Spring Boot App"与使用 "gradlew bootRun"运行 Spring Boot 应用程序有什么区别?

标签 spring-boot spring-mvc redis

Spring Boot 版本:2.1.5.RELEASE

我有一个简单的 Spring Boot MVC 应用程序,它使用 Redis 进行 spring session 存储。

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 安装作为 session 存储。我可以看到在 Redis 上添加的键 (keys *)。

但是,当我在命令提示符下使用 bootRun 运行它时,与 session 相关的一切似乎都工作正常,但我在 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

Tomcat 可以在使用 bootRun 运行时接管 session 管理吗?这是怎么发生的?

最佳答案

该死!看来这是我的错。我在 STS 中的项目已关闭。这是一个 Gradle 项目,我对该项目进行了一些更改,但不知道我必须执行“刷新 Gradle 项目”。无论如何,它们现在是同步的并且行为相似,但可悲的是它们都以错误的方式表现(不使用 Redis),但我想这是一个单独的问题。

关于spring-boot - "STS - Run As - Spring Boot App"与使用 "gradlew bootRun"运行 Spring Boot 应用程序有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56795859/

相关文章:

java - 使用 Gradle 时 Keycloak 无法加载提供程序类

java - 在 Spring boot 应用程序中传递常量消息的正确方法(messages.properties 或 Constant 类)

java - 将解析哪个 View ,来自 spring 文档的代码

ruby-on-rails - redis 实例是否只能用于 1 个项目?

python - 如何/在何处存储云应用程序的临时文件和日志?

graph - 如何将Redisgraph转换为networkx图以在Node2vec算法中使用?

spring - 在 Spring Boot 应用程序中禁用 Spring JMS 自动配置

java.lang.IllegalArgumentException : No converter found for return value of type

java - LDAP 获取用户所属的组

spring - 使用 Spring MVC Test 测试 Spring MVC @ExceptionHandler 方法