Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is ContextRefreshedEvent fired in Spring?

Tags:

spring

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?

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

like image 392
kennyg Avatar asked Oct 08 '16 16:10

kennyg


1 Answers

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--

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

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.

like image 124
kuhajeyan Avatar answered Sep 25 '22 13:09

kuhajeyan