SyntaxHighlighter

Saturday, August 31, 2013

Spring Application Context Events - ContextStartedEvent versus ContextRefreshedEvent

a recent question from a colleague spurred me to clarify the difference that between ContextStartedEvent and ContextRefreshedEvent.

ContextStartedEvent should be called at the completion of an ApplicationContext being started up.  however, when using it in different context scenarios, it doesn't appear to be triggered.  for instance, when using in JUnit in conjunction with SpringJUnit4ClassRunner, the event doesn't get fired.

ContextRefreshedEvent gets fired in almost every circumstance (haven't yet encountered one that doesn't).  so when an ApplicationContext starts up, ContextStartedEvent sometimes gets called, but ContextRefreshedEvent always gets called.  also, depending on the implementation of the ApplicationContext, refreshed is only called once with BeanFactory preventing refreshing, so it becomes analogous to Started.

Note: the principal ApplicationContexts used to formulate this are;
- ClassPathXmlApplicationContext
- AnnotationConfigApplicationContext
- GenericApplicationContext
- WebApplicationContext


No comments:

Post a Comment

Post a Comment