【问题标题】:Spring shared context in EAREAR 中的 Spring 共享上下文
【发布时间】:2020-12-24 21:48:33
【问题描述】:

我想要完成的是在一个罐子和两个战争之间共享 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 包含我想在两个战争之间共享的 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]

此外,在其中一场战争中,我有本地 spring 上下文,其中包含该特定战争本地的 bean。这些 bean 也已正确实例化:

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

bean 被正确注入到 jar 中的 bean 中。然而,没有注入 Struts 动作和 bean,位于前面提到的 Web 应用程序本地 bean(在 /WEB-INF/applicationContext.xml 中定义)。

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

我哪里错了?

提前感谢您的帮助。

【问题讨论】:

  • constantlearner,我看过那个帖子。我已经经历过瘦身战争,所以我认为这不是同一个问题。
  • 调试时,我注意到 Web 上下文已正确设置父上下文: Root WebApplicationContext: startup date [Fri Dec 20 11:22:45 CET 2013];父:ApplicationContext'mainApplicationContext'

标签: java spring jboss


【解决方案1】:

问题已解决。网络上下文已丢失

<context:annotation-config/>

注释。

【讨论】:

    【解决方案2】:
      <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 ?
    

    【讨论】:

    • 请解释为什么您的答案应该纠正问题中所述的问题
    猜你喜欢
    • 2013-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多