Retrieving applicationContext object using ApplicationContextAware interface implementation

Viewed 26

Said problem will get resolved if the class implementing ApplicationContextAware is marked with @Component annotation and class/residing package is mentioned as part of @ComponentScan annotation. If the class is not part of the scanned packages, then this won't work.

Do not want to initialise new Context as I need to extend the properties of the main application, is there any alternative for this. In short, I have an utility which is built with spring framework, callee application will also be implemented using Spring, but the utility does not have control over the packages that needs to be mentioned under @ComponentScan.

1 Answers

From the documentation, if we need to use any spring utility containing annotations, needs to be mentioned as part of @ComponentScan, at least the @Configuration bean of utility jar, so that it will scan further if there is anymore @ComponentScan annotations.

Note here that, it is not ideal to create separate ApplicationContext object as the dependent library is also part of the Spring application and ApplicationContext is initialised already during the startup of the application.

Above means, for the question raised here does not have direct solution.

Related