A ContextRefreshEvent occurs
when ApplicationContext initialized or updated.
so that you are on the right track.
What you need to do is declare a bean definition for classX .
Either using @Component or through component scan of a component in
@Component public classX implements ApplicationListener<ContextRefreshedEvent> { @Override public void onApplicationEvent(ContextRefreshedEvent event) {
or with the declaration <bean>
<bean class="some.pack.classX"></bean>
Spring will detect that the bean is of type ApplicationListener and register it without any additional configuration.
Just FYI, Java has naming conventions for types, variables, etc. For classes, the convention is that their names begin with an uppercase alphabetic character.
source share