Spring何时触发ContextRefreshedEvent? [英] When is ContextRefreshedEvent fired in Spring?

查看:976
本文介绍了Spring何时触发ContextRefreshedEvent?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道ApplicationContext完全加载后会被触发一次,但是在运行时之后呢? 刷新"一词意味着它将在刷新时触发,但我不知道Spring符合ApplicationContext刷新的资格吗?

I know that it is fired once when the ApplicationContext is fully loaded, but what about after that during runtime? The word "Refreshed" implies that it will be triggered on a refresh but I wonder what Spring qualifies as an ApplicationContext refresh?

后续问题: 并发线程可以触发此事件吗?我需要使此事件线程的EventHandler安全吗?

Followup question: Can this event be triggered by concurrent threads? Do I need to make the EventHandler for this event thread safe?

推荐答案

在加载/刷新属性,xml或任何架构文件时会触发,

it is fired when properties, xml or any schema files are loaded/refreshed, http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/support/AbstractApplicationContext.html#refresh--

加载或刷新配置的持久性表示形式, 可能是XML文件,属性文件或关系数据库 模式.

Load or refresh the persistent representation of the configuration, which might an XML file, properties file, or relational database schema.

它通常在春季被隐式触发,但是您应该能够在某些实例上触发它,但这是java doc所说的发生时间

It is fired implicitly by spring usually, but you should be able to fire that on certain instances, But here is java doc says when that happens

由于这是一种启动方法,因此应销毁已创建的方法 如果失败,则单身人士,以避免资源悬而未决.换一种说法, 调用该方法后,所有单例或根本没有单例 应该实例化.

As this is a startup method, it should destroy already created singletons if it fails, to avoid dangling resources. In other words, after invocation of that method, either all or no singletons at all should be instantiated.

这篇关于Spring何时触发ContextRefreshedEvent?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆