First create a class called AppContextManager
like
below:
@Component
public class AppContextManager implements ApplicationContextAware{
private static ApplicationContext _appCtx;
@Override
public void setApplicationContext(ApplicationContext ctx){
_appCtx = ctx;
}
public static ApplicationContext getAppContext(){
return _appCtx;
}
}
Annotate the above class with @Component
or
declare a bean for AppContextManager in your application
context xml
.
Now in your non-singleton
non-spring
instance
use the following code snippet to obtain any other spring bean:
ApplicationContext ctx = ApplicationContextManager.getAppContext();
SomeSpringBean bean = ctx.getBean(SomeSpringBean.class);
And this would give you the bean instance anywhere in your code.