March 14, 2006

Thinking about Spring Cross-WebApp niftyness with Fiona

What fun we had at LAMS.

The really critical bit that Chuck missed before:

./kernel/component/src/java/org/sakaiproject/component/kernel/component/ContextLoader.java

public class ContextLoader extends
org.springframework.web.context.ContextLoader
{

protected ApplicationContext loadParentContext(ServletContext servletContext)
throws BeansException
{
// get the component manager (we know it's a SpringCompMgr) and from that the shared AC
ConfigurableApplicationContext sharedAc = ((SpringCompMgr) ComponentManager
.getInstance()).getApplicationContext();

return sharedAc;
}
}

./kernel/component/src/java/org/sakaiproject/component/kernel/component/SpringCompMgr.java

public class SpringCompMgr implements ComponentManager

public synchronized void addChildAc()
{
m_childCount++;
}

public synchronized void removeChildAc()
{
m_childCount--;

// when we get back to 0, close our AC
if (m_childCount == 0)
{
close();
}
}

org.sakaiproject.util.ContextLoaderListener

./kernel/component/src/java/org/sakaiproject/util/ContextLoaderListener.java

public class ContextLoaderListener extends
org.springframework.web.context.ContextLoaderListener

public void contextInitialized(ServletContextEvent event)
{
super.contextInitialized(event);

// increment the count of children for the component manager
((SpringCompMgr) ComponentManager.getInstance()).addChildAc();
}

/**
* Close the root web application context.
*/
public void contextDestroyed(ServletContextEvent event)
{
super.contextDestroyed(event);

// decrement the count of children for the component manager
((SpringCompMgr) ComponentManager.getInstance()).removeChildAc();
}

./comp-test-app2/src/webapp/WEB-INF/web.xml


contextSharedLocation
/WEB-INF/shared.xml

...


org.sakaiproject.util.ContextLoaderListener

./comp-test-app2/src/webapp/WEB-INF/shared.xml

class="org.sakaiproject.component.test.components.Component6"
init-method="init"
destroy-method="destroy"
singleton="true">
[s6 c6 a2]

./kernel/component/src/config/org/sakaiproject/config/shared_components.xml

Posted by csev at March 14, 2006 02:50 AM