0

What I am trying to accomplish is sharing Spring context between one jar and two war's. All of them are packed in ear.

Here is beanRefContext.xml located in the jar:

<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 contains beans I would like to share between two war's.

Here is the web.xml in one war:

<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>

And similar in the other war.

From Jboss logs I can clearly see that all beans from main-applicationContext.xml are instantiated:

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

Moreover in one of the war's I have local spring context containing beans local to that particular war. Those beans are instantiated properly as well:

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

The beans are injected correctly into beans located in jar. However there are not injected into Struts actions and beans located in the mentioned earlier beans local for the web application (defined in /WEB-INF/applicationContext.xml).

What I would expect that beanRefContext.xml is parent context for local web context.

Where am I wrong?

Thank you in advance for any help.

Damian
  • 593
  • 6
  • 27
  • This may help you http://stackoverflow.com/questions/16162877/spring-mvc-sharing-context-within-ear – constantlearner Dec 20 '13 at 10:01
  • constantlearner, I've seen that post. I've already had skinny wars so I do not think it is the same issue. – Damian Dec 20 '13 at 10:11
  • When debugging, I noticed that web context has properly set parent context: Root WebApplicationContext: startup date [Fri Dec 20 11:22:45 CET 2013]; parent: ApplicationContext 'mainApplicationContext' – Damian Dec 20 '13 at 10:28

2 Answers2

0

Issue solved. Web context has been missing

<context:annotation-config/>

annotation.

Damian
  • 593
  • 6
  • 27
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 ?
  • 2
    Please add an explanation why your answer should correct the problem stated in the question – Steve Dec 24 '20 at 13:21