Thanks for comments.
I found the solution in one of the annotations supplied by Spring Framework.
Solution of @DependsOn
annotation worked. Actually when I was using @Bean above getter method of ApplicationContext
it was firing exception as mentioned in the question. Then I read the documentation of @DependsOn
annotation. It states that this annotation is applicable on @Bean and @Component. As the class in which ApplicationContext
was being injected, I've made ClassA @DependsOn
the @Component
class where ApplicationContext
is being injected and it works.
Thanks again for your comments.