applicationContext = (ConfigurableWebApplicationContext) loader
.initWebApplicationContext(servletContext);
logger.debug("Root context path: "
+ applicationContext.getServletContext().getContextPath());
ConfigurableBeanFactory factory = applicationContext
.getBeanFactory();
// register default
factory.registerSingleton("default.context", applicationContext);
// get the main factory
parentFactory = (DefaultListableBeanFactory) factory
.getParentBeanFactory();
// create a wrapper around our primary context
BeanFactoryReference beanfactoryRef = new ContextBeanFactoryReference(
applicationContext);
// set it in the root servlet context
servletContext.setAttribute("bean.factory.ref", beanfactoryRef);
// set a remoting codec factory for AMF use
servletContext.setAttribute("remoting.codec.factory", parentFactory
.getBean("remotingCodecFactory"));
server = (Server) parentFactory.getBean("red5.server");
clientRegistry = (ClientRegistry) factory
.getBean("global.clientRegistry");
globalInvoker = (ServiceInvoker) factory
.getBean("global.serviceInvoker");
globalStrategy = (MappingStrategy) factory
.getBean("global.mappingStrategy");
global = (GlobalScope) factory.getBean("global.scope");
logger.debug("GlobalScope: " + global);
global.setServer(server);
global.register();
global.start();
globalResolver = new ScopeResolver();
globalResolver.setGlobalScope(global);
logger.debug("About to grab Webcontext bean for Global");
Context globalContext = (Context) factory.getBean("global.context");
globalContext.setCoreBeanFactory(parentFactory);
globalContext.setClientRegistry(clientRegistry);
globalContext.setServiceInvoker(globalInvoker);
globalContext.setScopeResolver(globalResolver);
globalContext.setMappingStrategy(globalStrategy);
logger.debug("About to grab Webcontext bean for ROOT");
Context webContext = (Context) factory.getBean("web.context");
webContext.setCoreBeanFactory(parentFactory);
webContext.setClientRegistry(clientRegistry);
webContext.setServiceInvoker(globalInvoker);
webContext.setScopeResolver(globalResolver);
webContext.setMappingStrategy(globalStrategy);
WebScope scope = (WebScope) factory.getBean("web.scope");
scope.setServer(server);
scope.setParent(global);
scope.register();
scope.start();