java - @PostConstruct sleep 时不会触发 ContextClosedEvent

标签 java spring spring-boot

来自 Spring @Component , @PostConstruct ,如果主线程进入 hibernate 状态,例如 30 秒。

在这之间,运行 kill <pid> 会触发 SIGTERM

但在这种情况下 @PreDestroy 都不是,也不是EventListenerContextClosedEvent被触发。

我们可以监听哪个 Spring 核心事件的日志,例如当一个 bean 正在 hibernate 时 PostConstruct并且 SIGTERM 被发送到 spring boot 应用程序?

最佳答案

根据评论之一,问题是 @PostConstruct 中的逻辑太多

so your problem is actually that you're performing too much work in @PostConstruct

Said another way, since Spring is still in the process of initializing itself, it probably hasn't even gotten to the step of the initialization process where if registers the shutdown hook, so it is never even notified about the SIGTERM

关于java - @PostConstruct sleep 时不会触发 ContextClosedEvent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58833334/

相关文章:

java - Spring hibernate : @Transaction (REQUIRES_NEW) not catching exception

java - 为什么spring源代码中的 "NestedExceptionUtils"被声明为抽象类?

java - spring boot 的 netty 上下文路径

java - 使用 jar 中的@entity 时,Spring Data Jpa Repository 不工作

java - 如何使用带动态参数的 spring DI 构造函数

java - 关于servlet映射的基本问题

java - 按多个属性对对象排序

java - svg 文件在 android 中呈现

Java,根据关键字对多维数组进行排序

java - 除了 Spring boot 一次输入的 Pageable 和 Sort 之外,对所有参数使用 @Param