I've got something that seems to do what I want. I'll post the relevant bits of code here in the hope that
a) If it's not good practice someone can tell me; and
b) If it's OK, it may be a useful example.
The constructor of the schdulable object in my sar:
Code:
public OrderUnload()
{
// do it this way to make the beanFactory available to web modules:
BeanFactoryLocator bfl = SingletonBeanFactoryLocator.getInstance();
BeanFactoryReference bfr = bfl.useBeanFactory("org.stl.wo.appcontext");
setUnloader((OrderUnloader)bfr.getFactory().getBean("orderUnloader"));
//to prevent classloader problems on hot redeploy:
bfr.release();
}
The DespatcherServlet for my web module:
Code:
public class CustomContextDispatcherServlet extends DispatcherServlet {
BeanFactoryReference bfr = null;
protected WebApplicationContext initWebApplicationContext() {
ContextLoader cl = new MyContextLoader();
WebApplicationContext wac = cl.initWebApplicationContext(this.getServletContext());
getServletContext().setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.woapp", wac);
return wac;
}
public void destroy() {
// to prevent classloader problems on hot redeploy:
if (bfr != null) {
bfr.release();
}
}
class MyContextLoader extends ContextLoader {
protected ApplicationContext loadParentContext(ServletContext servletContext) {
BeanFactoryLocator bfl = SingletonBeanFactoryLocator.getInstance();
bfr = bfl.useBeanFactory("org.stl.wo.appcontext");
return (ApplicationContext)bfr.getFactory();
}
}
}
I found the calls to release() on the BeanFactoryReference to be necessary to prevent classloader problems on hot redeploy of the application.