- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 Spring 5.x 中,以下事件有什么区别?
ServletContextListener.contextInitialized(ServletContextEvent)
;和 ServletContextListener.contextDestroyed(ServletContextEvent)
? ContextRefreshedEvent
中完成吗?或 ContextStartedEvent
? ContextClosedEvent
中完成,我也想尽可能晚地销毁它。或 ContextStoppedEvent
? 最佳答案
这些内置事件的文档可以在 here 中找到。 , 具体来说:
ContextRefreshedEvent
Published when the ApplicationContext is initialized or refreshed (for example, by using the refresh() method on the ConfigurableApplicationContext interface). Here, “initialized” means that all beans are loaded, post-processor beans are detected and activated, singletons are pre-instantiated, and the ApplicationContext object is ready for use. As long as the context has not been closed, a refresh can be triggered multiple times, provided that the chosen ApplicationContext actually supports such “hot” refreshes. For example, XmlWebApplicationContext supports hot refreshes, but GenericApplicationContext does not.
ContextStartedEvent
Published when the ApplicationContext is started by using the start() method on the ConfigurableApplicationContext interface. Here, “started” means that all Lifecycle beans receive an explicit start signal. Typically, this signal is used to restart beans after an explicit stop, but it may also be used to start components that have not been configured for autostart (for example, components that have not already started on initialization).
ContextStoppedEvent
Published when the ApplicationContext is stopped by using the stop() method on the ConfigurableApplicationContext interface. Here, “stopped” means that all Lifecycle beans receive an explicit stop signal. A stopped context may be restarted through a start() call.
ContextClosedEvent
Published when the ApplicationContext is closed by using the close() method on the ConfigurableApplicationContext interface. Here, “closed” means that all singleton beans are destroyed. A closed context reaches its end of life. It cannot be refreshed or restarted.
RequestHandledEvent
A web-specific event telling all beans that an HTTP request has been serviced. This event is published after the request is complete. This event is only applicable to web applications that use Spring’s DispatcherServlet.
ContextRefreshedEvent
和
ContextClosedEvent
.其他两个仅在您调用
start()
时才发送。或
stop()
在应用程序上下文中,因此您不想使用它们。
org.springframework.boot.logging.LoggingSystem
),它定义了
beforeInitialize
,
initalize
, 和
cleanUp
方法,还有一个
shutdownHandler
JVM 存在时调用。
org.springframework.boot.context.logging.LoggingApplicationListener
以供引用。 Spring Boot 自带
additional application events .日志系统的初始化似乎是在
ApplicationEnvironmentPreparedEvent
上完成的。 .清理在
ContextClosedEvent
上完成和
ApplicationFailedEvent
.
关于spring - ContextRefreshedEvent、ContextStartedEvent、ContextStoppedEvent 和 ContextClosedEvent 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47134189/
我想测试像 Example 这样的类,它处理 ContextRefreshedEvent 并在处理程序方法中连接到服务器: public class Example { @EventListe
我创建了 Spring 应用程序,并且正在独立的 Java 应用程序中加载应用程序上下文。我的代码如下 public class Application { public static voi
我正在尝试 ApplicationListener,但每次都会调用 ContextRefreshedEvent。我想知道何时调用 ContextStartedEvent。 public class C
我知道它会在 ApplicationContext 完全加载时触发一次,但是在运行时之后呢? “Refreshed”一词意味着它将在刷新时触发,但我想知道 Spring 有什么资格作为 Applica
我注册了一个 Spring ApplicationListener bean 来监听 ContextRefreshed 事件。不过,出于某种奇怪的原因,在上下文初始化完成时,我得到了对 onApp
我提出了两种情况,一种是使用 bean 工厂注册的 bean,另一种是通过自动扫描包中的注释定义(例如 @Component)创建的 bean。 bean 类使用用 @EventListener 和
在 Spring 5.x 中,以下事件有什么区别? 上下文刷新事件 上下文启动事件 上下文停止事件 上下文关闭事件 哪个事件与 servlet 上下文事件相关(根据 https://docs.orac
我想为此私有(private)方法创建 JUnit 测试: @Component public class ReportingProcessor { @EventListener pr
我试图在应用程序首次启动时进行一些数据库清理。首先,我定义了 JNDI 连接,如下所示: @Bean public TomcatEmbeddedServletContainerFactory tomc
我有一个 bean (SettingService),它用 @Transactional 注释装饰并注入(inject)到另一个 bean 中,在上下文刷新事件中调用这个 bean。 public c
我是一名优秀的程序员,十分优秀!