EAR中的Spring共享上下文

时间:2013-12-20 09:40:20

标签: java spring jboss

我想要完成的是在一个jar和两个war之间共享Spring上下文。所有这些都装在耳边。

这是位于jar中的beanRefContext.xml:

<bean id="mainApplicationContext"
    class="org.springframework.context.support.ClassPathXmlApplicationContext">
    <constructor-arg>
        <list>
            <value>/META-INF/spring/main-applicationContext.xml</value>
        </list>
    </constructor-arg>
</bean>

main-applicationContext.xml包含我想在两个war之间共享的bean。

这是一场战争中的web.xml:

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listenerclass>
</listener>

<context-param>
    <param-name>locatorFactorySelector</param-name>
    <param-value>/META-INF/spring/beanRefContext.xml</param-value>
</context-param>

<context-param>
    <param-name>parentContextKey</param-name>
    <param-value>mainApplicationContext</param-value>
</context-param>

在另一场战争中也是如此。

从Jboss日志中我可以清楚地看到main-applicationContext.xml中的所有bean都被实例化了:

[org.springframework.beans.factory.xml.XmlBeanDefinitionReader] Loaded 265 bean definitions from location pattern [/META-INF/spring/main-applicationContext.xml]

此外,在其中一场战争中,我有当地的春季背景,其中包含特定战争的本地豆类。那些bean也可以正确实例化:

[org.springframework.beans.factory.xml.XmlBeanDefinitionReader] Loaded 55 bean definitions from location pattern [/WEB-INF/applicationContext.xml]

将豆子正确注入罐子里的豆子里。但是,没有注入位于上面提到的Web应用程序本地bean的Struts操作和bean中(在/WEB-INF/applicationContext.xml中定义)。

我期望beanRefContext.xml是本地Web上下文的父上下文。

我哪里错了?

提前感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

问题解决了。 Web上下文一直缺失

<context:annotation-config/>

注释

答案 1 :(得分:0)

  <context-param>
        <param-name>locatorFactorySelector</param-name>
        <param-value>classpath*:/META-INF/spring/beanRefContext.xml</param-value>
    </context-param>
     <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
can you try the above statements once in your web.xml file ?
相关问题