Ok, got it to work.
I basically did my own JNDI resource factory that just returns the spring bean factory.
http://jakarta.apache.org/tomcat/tom...ces-howto.html
Only caveat was that you can't have spring.jar in your WEB-INF/lib and common/lib or you'll get ClassCastExceptions (the same may apply for your resource factory class and spring beans, I had them only in common/classes).
Will have to see how to solve this if I need spring directly in my webapp.
Code:
public class BeanFactory implements ObjectFactory {
private static XmlBeanFactory bf;
static {
ClassPathResource res = new ClassPathResource("applicationContext.xml");
bf = new XmlBeanFactory(res);
}
public Object getObjectInstance(Object obj,
Name name, Context nameCtx, Hashtable environment)
throws NamingException {
return bf;
}
}
The following is in tomcat's server.xml in the appropriate locations.
Code:
<GlobalNamingResources>
<Resource name="spring/beanFactory" auth="Container"
type="org.springframework.beans.factory.xml.XmlBeanFactory"/>
<ResourceParams name="spring/beanFactory">
<parameter>
<name>factory</name>
<value>contextTest.BeanFactory</value>
</parameter>
</ResourceParams>
</GlobalNamingResources>
Code:
<Context path="/second" docBase="../build2" debug="0" reloadable="true">
<ResourceLink name="spring/beanFactory"
global="spring/beanFactory"
type="org.springframework.beans.factory.xml.XmlBeanFactory"/>
</Context>