Now I've found a solution, which matchs to my needs. At the end of method afterPropertiesSet of the beanservlet I prepare the SimpleUrlHandlerMapping by creating an instance of it without Spring and register it as a singleton on the desired ApplicationContext. This looks like the following:
Code:
AbstractRefreshableWebApplicationContext parentAppContext
= (AbstractRefreshableWebApplicationContext) myApplicationContextWhichWasUsedToCreateTheCurrentBean;
ConfigurableListableBeanFactory configurableBeanFactory = parentAppContext.getBeanFactory();
configurableBeanFactory.registerSingleton("handlerMappingForBean" + myBeanName, myUrlMappingBean);
An important thing is, that the beanservlet implements the interface FactoryBean. So you have to possibility to interact, when the bean initialization is finished. Before I return the object on method getObject I do some finally work like telling "myUrlMappingBean" to which ApplicationContext it belongs. This has to be done at this point to prevent a circular dependency. The code looks like the following:
Code:
private boolean myUrlMappingBeanInitialized = false
public Object getObject() throws Exception {
/**
* If the url mapping is not already allocated to the application, this
* will be done here. This allocation will be done only once.
*/
if (myUrlMappingBean != null && !myUrlMappingBeanInitialized) {
myUrlMappingBeanInitialized = true;
m_urlMapping.setApplicationContext(myApplicationContextWhichWasUsedToCreateTheCurrentBean);
}
return myServletBean;
}
Comments are welcome!
Cheers,
Martin