spring监听器会对某一些事件的触发进行监听:
例如:ContextClosedEvent(容器关闭时)
ContextRefreshedEvent(容器刷新时)
ContextStartedEvent(容器启动时候)
ContextStoppedEvent(容器停止的时候)
我想知道的是容器什么时候会刷新?网上复制的答案就别来了,看过了。
spring监听器会对某一些事件的触发进行监听:
例如:ContextClosedEvent(容器关闭时)
ContextRefreshedEvent(容器刷新时)
ContextStartedEvent(容器启动时候)
ContextStoppedEvent(容器停止的时候)
我想知道的是容器什么时候会刷新?网上复制的答案就别来了,看过了。
15 回答8.4k 阅读
8 回答6.2k 阅读
1 回答4.1k 阅读✓ 已解决
3 回答2.2k 阅读✓ 已解决
2 回答3.1k 阅读
2 回答3.8k 阅读
3 回答1.7k 阅读✓ 已解决
这些东西最好去看文档。
可以spring 的官网看下文档,https://docs.spring.io/spring... 我这里截取下
ContextRefreshedEvent的说明:
Published when the ApplicationContext is initialized or refreshed, for example, using the refresh() method on the ConfigurableApplicationContext interface. "Initialized" here 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.
从说明中可以看出,当容器中的bean初始化好的时候,会回调ContextRefreshedEvent事件一次,
你也可以手动调用容器提供的refresh()方法,去触发ContextRefreshedEvent事件。