无法使用 Spring 5.2.x 引用不同的 xml

发布于 2025-01-12 09:39:53 字数 13311 浏览 0 评论 0原文

在 Spring 4.3.5 中,我们一直在使用一种应用程序架构,在该架构中,我们一次性初始化一些 bean,然后使用这些 bean 作为其他 bean 的“引用”。

<bean id="handleUncheckedEndpointExceptionAdvice" 
    class="com.gehcit.cp.ws.infrastructure.aop.advices.HandleUncheckedEndpointExceptionAdvice">
    <constructor-arg ref="exceptionFactory"/>
    <property name="exceptionSenderService" ref="exceptionSenderService" />
</bean>

但是一旦我们将库升级到 Spring 5.2.x,我们就开始在 Jboss 7.3.1 启动时出现以下异常:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'handleUncheckedEndpointExceptionAdvice' defined in ServletContext resource [/WEB-INF/context-web.xml]: Cannot resolve reference to bean 'exceptionSenderService' while setting bean property 'exceptionSenderService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'exceptionSenderService' available

我所做的一切: 启用 TRACE 日志记录并发现此 - 2022-03-05 13:09:39,927 TRACE [org.springframework.beans.factory.annotation.InjectionMetadata] (ServerService Thread Pool -- 65) 处理 bean 'exceptionSenderService' 的注入元素:私有 com.gehcit.cp.serviceability.service.ExceptionSenderService 的 AutowiredFieldElement com.gehcit.cp.cem.aplix.jms.service.Impl.AplixPublisherQueueServiceImpl.exceptionSender 2022-03-05 13:09:39,927 TRACE [org.springframework.beans.factory.support.DefaultListableBeanFactory](ServerService 线程池 - 65 ) 返回单例 bean 的缓存实例'exceptionSenderServiceImpl' 2022-03-05 13:09:39,927 TRACE [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (ServerService 线程池 -- 65) 按类型从 bean 名称 'exceptionSenderService' 自动装配到名为 'exceptionSenderServiceImpl' 的 bean 现在 bean 正在初始化,但是当从 Spring 缓存中搜索引用时,我们什么也得不到。

但后来我们尝试将 bean 初始化从不同的 xml 转移到引用 bean 且有效的同一个 xml 中。因此我们得出的结论是,跨 XML 配置不知何故不起作用。

从 context-web.xml 引用 Bean

<?xml version="1.0"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:util="http://www.springframework.org/schema/util" 
    xmlns:cxf="http://cxf.apache.org/core" 
    xmlns:jaxws="http://cxf.apache.org/jaxws" 
    xmlns:jaxrs="http://cxf.apache.org/jaxrs" 
    xmlns:task="http://www.springframework.org/schema/task" 
    xmlns:security="http://www.springframework.org/schema/security"
    xmlns:oauth2="http://www.springframework.org/schema/security/oauth2" 
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
        http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
        http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
        http://www.springframework.org/schema/security 
            https://www.springframework.org/schema/security/spring-security.xsd
        http://www.springframework.org/schema/security/oauth2 
            https://www.springframework.org/schema/security/spring-security-oauth2.xsd">

    <task:annotation-driven/>
    <!-- Define placeholder for application properties -->
    <bean 
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>/WEB-INF/web.properties</value>
                <value>classpath:application.properties</value>
            </list>
        </property>
    </bean>
    <!-- Load CXF modules from cxf.jar -->
    <import resource="classpath:META-INF/cxf/cxf.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
    <import resource="context-cem-web.xml"/>
    <!-- define an auto-proxy generator for our advisors -->
    <bean 
        class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator">
        <property name="proxyTargetClass" value="false"/>
    </bean>
    <!-- id generator for exceptions -->
    <bean id="exceptionIdGenerator" 
        class="com.gehcit.cp.ws.infrastructure.exception.HostTimeExceptionIdGenerator">
        <property name="prefix" value="CEN"/>
    </bean>
    <!-- system fault factory -->
    <bean id="systemFaultFactory" 
        class="com.gehcit.cp.ws.infrastructure.exception.StandardSystemFaultFactory">
        <property name="exceptionIdGenerator" ref="exceptionIdGenerator"/>
        <property name="appendExceptionIdToErrorMessage" value="true"/>
    </bean>
    <bean id="defaultParamConverterProvider"
        class="org.apache.cxf.jaxrs.ext.search.DefaultParamConverterProvider"/>
    <!-- factory for mapping runtime exceptions to wire faults -->
    <bean id="exceptionFactory" 
        class="com.gehcit.cp.ws.infrastructure.exception.ExceptionMapperExceptionFactory">
        <property name="exceptionMappers">
            <list>
                <bean 
                    class="com.gehcit.cp.ws.infrastructure.exception.IllegalArgumentFaultFromIllegalArgumentExceptionMapper"/>
                <bean 
                    class="com.gehcit.cp.ws.infrastructure.exception.SecurityFaultFromCPSecurityExceptionMapper"/>
                <bean 
                    class="com.gehcit.cp.ws.infrastructure.exception.ApplicationFaultFromApplicationErrorMapper"/>
                <bean 
                    class="com.gehcit.cp.ws.infrastructure.exception.SystemFaultFromRuntimeExceptionMapper">
                    <constructor-arg ref="systemFaultFactory"/>
                </bean>
            </list>
        </property>
    </bean>
    <!-- aspect for handling unchecked endpoint exceptions -->
    <bean id="handleUncheckedEndpointExceptionAdvice" 
        class="com.gehcit.cp.ws.infrastructure.aop.advices.HandleUncheckedEndpointExceptionAdvice">
        <constructor-arg ref="exceptionFactory"/>
        <property name="exceptionSenderService" ref="exceptionSenderService" />
    </bean>
    <bean id="handleUncheckedEndpointExceptionPointcut" 
        class="org.springframework.aop.support.annotation.AnnotationMatchingPointcut">
        <constructor-arg type="java.lang.Class">
            <null/>
        </constructor-arg>
        <constructor-arg type="java.lang.Class" 
            value="com.gehcit.cp.ws.infrastructure.aop.annotations.HandleUncheckedEndpointException"/>
    </bean>
    <bean id="handleUncheckedEndpointExceptionAdvisor" 
        class="org.springframework.aop.support.DefaultPointcutAdvisor">
        <property name="advice" ref="handleUncheckedEndpointExceptionAdvice"/>
        <property name="pointcut" 
            ref="handleUncheckedEndpointExceptionPointcut"/>
    </bean>

该 Bean 正在 context-applix.xml 中初始化

    <beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:amq="http://activemq.apache.org/schema/core" 
    xmlns:jms="http://www.springframework.org/schema/jms" 
    xmlns:p="http://www.springframework.org/schema/p" 
    xsi:schemaLocation="
                  http://www.springframework.org/schema/beans 
                  http://www.springframework.org/schema/beans/spring-beans.xsd
                  http://activemq.apache.org/schema/core
                  http://activemq.apache.org/schema/core/activemq-core.xsd
                  http://www.springframework.org/schema/beans 
                  http://www.springframework.org/schema/beans/spring-beans.xsd
                  http://www.springframework.org/schema/jms 
                  http://www.springframework.org/schema/jms/spring-jms.xsd">
    <!-- Activemq connection factory start -->
    <bean id ="connectionAmqFactory" 
        class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" 
            value="vm://broker#{T(com.gehcit.cp.ws.ServiceProperties).instance().getProperty(T(com.gehcit.cp.Constants).CENTRICITY_DEPLOY_ID)}-applix" 
            />
    </bean>
    <!-- A POJO that implements the JMS message listener -->
    <bean id="aplixSubscriberQueueService" 
        class="com.gehcit.cp.cem.aplix.jms.listener.AplixSubscriberQueueListener" 
        />
    <bean id="exceptionSenderService" 
        class="com.gehcit.cp.cem.aplix.jms.service.Impl.AplixPublisherQueueServiceImpl" 
        />
    <!-- A destination in ActiveMQ -->
    <!--amq:topic id="destination" physicalName="APLIX.ERRORINFO" /-->
    <!-- A destination in ActiveMQ -->
    <amq:queue id="destination" physicalName="APLIX.ERRORINFO" />
    <!-- A destination in ActiveMQ end-->
    <!-- A cached connection to wrap the ActiveMQ connection -->
    <bean id="cachedAmqConnectionFactory" 
        class="org.springframework.jms.connection.CachingConnectionFactory" 
        p:targetConnectionFactory-ref="connectionAmqFactory" 
        p:sessionCacheSize="10" />
    <!-- Adding JMS transaction Manager -->
    
    <bean id="TransactionManager" 
        class="org.springframework.jms.connection.JmsTransactionManager">
        <property name="connectionFactory" ref="cachedAmqConnectionFactory"/>
    </bean>
    <!-- Adding JMS transaction Manager -End -->
    <!-- A JmsTemplate instance that uses the connection and destination -->
    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate" 
        p:connectionFactory-ref="cachedAmqConnectionFactory" 
        p:defaultDestination-ref="destination" />
    <!-- A JmsTemplate instance that uses the connection and destination end -->
    <!--Cofiguring JMS container and listener-->
    <jms:listener-container container-type="default" 
        connection-factory="cachedAmqConnectionFactory" destination-type="queue" >
        <jms:listener destination="APLIX.ERRORINFO" 
            ref="aplixSubscriberQueueService" method="onMessage" />
    </jms:listener-container>
    <!--Cofiguring JMS container and listener end-->
    <!-- The Spring message listener container configuration -->
    <amq:broker start="true" persistent="false" 
        brokerName="broker#{T(com.gehcit.cp.ws.ServiceProperties).instance().getProperty(T(com.gehcit.cp.Constants).CENTRICITY_DEPLOY_ID)}-applix" 
        deleteAllMessagesOnStartup="false" >
        <amq:managementContext>
            <amq:managementContext createConnector="false"/>
        </amq:managementContext>
        <amq:systemUsage>
            <amq:systemUsage>
                <amq:memoryUsage>
                    <amq:memoryUsage limit="512 mb"/>
                </amq:memoryUsage>
                <amq:tempUsage>
                    <amq:tempUsage limit="2 gb"/>
                </amq:tempUsage>
            </amq:systemUsage>
        </amq:systemUsage>      
        <amq:transportConnectors>
            <amq:transportConnector name="vm" 
                uri="vm://broker#{T(com.gehcit.cp.ws.ServiceProperties).instance().getProperty(T(com.gehcit.cp.Constants).CENTRICITY_DEPLOY_ID)}-applix"/>
        </amq:transportConnectors>
    </amq:broker>
</beans>

有人可以帮我找到一种从其他 xml 引用 Bean 的方法吗Spring 5.2.x 中的文件。 注意:我们在 Spring 5.2 中更改了类加载部分。

将其添加到 web.xml

    <listener-class>com.gehcit.cp.ws.infrastructure.security.BeanFactoryContextLoaderListener</listener-class>
</listener>
<!-- <context-param>
    <param-name>locatorFactorySelector</param-name>
    <param-value>/beanRefFactory.xml</param-value>
</context-param>  -->

BeanFactoryContextLoaderListener.java

package com.gehcit.cp.ws.infrastructure.security;
import javax.servlet.ServletContext;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
public class BeanFactoryContextLoaderListener extends ContextLoaderListener {
private static Logger log = Logger.getLogger(BeanFactoryContextLoaderListener.class)     
    @Override
        protected ApplicationContext loadParentContext(ServletContext servletContext) { 
         log.info("Entered loadParentContext");    
         ApplicationContext ctx = new ClassPathXmlApplicationContext("beanRefFactory.xml");
         log.info("Exit loadParentContext" + ctx.toString());
         return ctx;
        }
}

这与我无法解决的 ApplicationContext 有关。

With Spring 4.3.5, we have been using an application architecture where we initialize some of the beans at a go and then use the beans as "Reference" for other beans.

Something like this

<bean id="handleUncheckedEndpointExceptionAdvice" 
    class="com.gehcit.cp.ws.infrastructure.aop.advices.HandleUncheckedEndpointExceptionAdvice">
    <constructor-arg ref="exceptionFactory"/>
    <property name="exceptionSenderService" ref="exceptionSenderService" />
</bean>

But once we upgraded our library to Spring 5.2.x, we started getting the below exception at Jboss 7.3.1 startup:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'handleUncheckedEndpointExceptionAdvice' defined in ServletContext resource [/WEB-INF/context-web.xml]: Cannot resolve reference to bean 'exceptionSenderService' while setting bean property 'exceptionSenderService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'exceptionSenderService' available

What all I did:
Enabled TRACE logging and found this - 2022-03-05 13:09:39,927 TRACE [org.springframework.beans.factory.annotation.InjectionMetadata] (ServerService Thread Pool -- 65) Processing injected element of bean 'exceptionSenderService': AutowiredFieldElement for private com.gehcit.cp.serviceability.service.ExceptionSenderService com.gehcit.cp.cem.aplix.jms.service.Impl.AplixPublisherQueueServiceImpl.exceptionSender 2022-03-05 13:09:39,927 TRACE [org.springframework.beans.factory.support.DefaultListableBeanFactory] (ServerService Thread Pool -- 65) Returning cached instance of singleton bean 'exceptionSenderServiceImpl' 2022-03-05 13:09:39,927 TRACE [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (ServerService Thread Pool -- 65) Autowiring by type from bean name 'exceptionSenderService' to bean named 'exceptionSenderServiceImpl'
Now the bean is getting initialized but when the reference is being searched, being searched from the Spring cache, we get nothing.

But then we tried shifting the bean initialization from a different xml to the same xml where the bean is being referred and that worked. So we concluded that somehow the cross XML configurations are not working.

Bean being referred from context-web.xml

<?xml version="1.0"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:util="http://www.springframework.org/schema/util" 
    xmlns:cxf="http://cxf.apache.org/core" 
    xmlns:jaxws="http://cxf.apache.org/jaxws" 
    xmlns:jaxrs="http://cxf.apache.org/jaxrs" 
    xmlns:task="http://www.springframework.org/schema/task" 
    xmlns:security="http://www.springframework.org/schema/security"
    xmlns:oauth2="http://www.springframework.org/schema/security/oauth2" 
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
        http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
        http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
        http://www.springframework.org/schema/security 
            https://www.springframework.org/schema/security/spring-security.xsd
        http://www.springframework.org/schema/security/oauth2 
            https://www.springframework.org/schema/security/spring-security-oauth2.xsd">

    <task:annotation-driven/>
    <!-- Define placeholder for application properties -->
    <bean 
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>/WEB-INF/web.properties</value>
                <value>classpath:application.properties</value>
            </list>
        </property>
    </bean>
    <!-- Load CXF modules from cxf.jar -->
    <import resource="classpath:META-INF/cxf/cxf.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
    <import resource="context-cem-web.xml"/>
    <!-- define an auto-proxy generator for our advisors -->
    <bean 
        class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator">
        <property name="proxyTargetClass" value="false"/>
    </bean>
    <!-- id generator for exceptions -->
    <bean id="exceptionIdGenerator" 
        class="com.gehcit.cp.ws.infrastructure.exception.HostTimeExceptionIdGenerator">
        <property name="prefix" value="CEN"/>
    </bean>
    <!-- system fault factory -->
    <bean id="systemFaultFactory" 
        class="com.gehcit.cp.ws.infrastructure.exception.StandardSystemFaultFactory">
        <property name="exceptionIdGenerator" ref="exceptionIdGenerator"/>
        <property name="appendExceptionIdToErrorMessage" value="true"/>
    </bean>
    <bean id="defaultParamConverterProvider"
        class="org.apache.cxf.jaxrs.ext.search.DefaultParamConverterProvider"/>
    <!-- factory for mapping runtime exceptions to wire faults -->
    <bean id="exceptionFactory" 
        class="com.gehcit.cp.ws.infrastructure.exception.ExceptionMapperExceptionFactory">
        <property name="exceptionMappers">
            <list>
                <bean 
                    class="com.gehcit.cp.ws.infrastructure.exception.IllegalArgumentFaultFromIllegalArgumentExceptionMapper"/>
                <bean 
                    class="com.gehcit.cp.ws.infrastructure.exception.SecurityFaultFromCPSecurityExceptionMapper"/>
                <bean 
                    class="com.gehcit.cp.ws.infrastructure.exception.ApplicationFaultFromApplicationErrorMapper"/>
                <bean 
                    class="com.gehcit.cp.ws.infrastructure.exception.SystemFaultFromRuntimeExceptionMapper">
                    <constructor-arg ref="systemFaultFactory"/>
                </bean>
            </list>
        </property>
    </bean>
    <!-- aspect for handling unchecked endpoint exceptions -->
    <bean id="handleUncheckedEndpointExceptionAdvice" 
        class="com.gehcit.cp.ws.infrastructure.aop.advices.HandleUncheckedEndpointExceptionAdvice">
        <constructor-arg ref="exceptionFactory"/>
        <property name="exceptionSenderService" ref="exceptionSenderService" />
    </bean>
    <bean id="handleUncheckedEndpointExceptionPointcut" 
        class="org.springframework.aop.support.annotation.AnnotationMatchingPointcut">
        <constructor-arg type="java.lang.Class">
            <null/>
        </constructor-arg>
        <constructor-arg type="java.lang.Class" 
            value="com.gehcit.cp.ws.infrastructure.aop.annotations.HandleUncheckedEndpointException"/>
    </bean>
    <bean id="handleUncheckedEndpointExceptionAdvisor" 
        class="org.springframework.aop.support.DefaultPointcutAdvisor">
        <property name="advice" ref="handleUncheckedEndpointExceptionAdvice"/>
        <property name="pointcut" 
            ref="handleUncheckedEndpointExceptionPointcut"/>
    </bean>

The bean is being initialized in context-applix.xml

    <beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:amq="http://activemq.apache.org/schema/core" 
    xmlns:jms="http://www.springframework.org/schema/jms" 
    xmlns:p="http://www.springframework.org/schema/p" 
    xsi:schemaLocation="
                  http://www.springframework.org/schema/beans 
                  http://www.springframework.org/schema/beans/spring-beans.xsd
                  http://activemq.apache.org/schema/core
                  http://activemq.apache.org/schema/core/activemq-core.xsd
                  http://www.springframework.org/schema/beans 
                  http://www.springframework.org/schema/beans/spring-beans.xsd
                  http://www.springframework.org/schema/jms 
                  http://www.springframework.org/schema/jms/spring-jms.xsd">
    <!-- Activemq connection factory start -->
    <bean id ="connectionAmqFactory" 
        class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" 
            value="vm://broker#{T(com.gehcit.cp.ws.ServiceProperties).instance().getProperty(T(com.gehcit.cp.Constants).CENTRICITY_DEPLOY_ID)}-applix" 
            />
    </bean>
    <!-- A POJO that implements the JMS message listener -->
    <bean id="aplixSubscriberQueueService" 
        class="com.gehcit.cp.cem.aplix.jms.listener.AplixSubscriberQueueListener" 
        />
    <bean id="exceptionSenderService" 
        class="com.gehcit.cp.cem.aplix.jms.service.Impl.AplixPublisherQueueServiceImpl" 
        />
    <!-- A destination in ActiveMQ -->
    <!--amq:topic id="destination" physicalName="APLIX.ERRORINFO" /-->
    <!-- A destination in ActiveMQ -->
    <amq:queue id="destination" physicalName="APLIX.ERRORINFO" />
    <!-- A destination in ActiveMQ end-->
    <!-- A cached connection to wrap the ActiveMQ connection -->
    <bean id="cachedAmqConnectionFactory" 
        class="org.springframework.jms.connection.CachingConnectionFactory" 
        p:targetConnectionFactory-ref="connectionAmqFactory" 
        p:sessionCacheSize="10" />
    <!-- Adding JMS transaction Manager -->
    
    <bean id="TransactionManager" 
        class="org.springframework.jms.connection.JmsTransactionManager">
        <property name="connectionFactory" ref="cachedAmqConnectionFactory"/>
    </bean>
    <!-- Adding JMS transaction Manager -End -->
    <!-- A JmsTemplate instance that uses the connection and destination -->
    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate" 
        p:connectionFactory-ref="cachedAmqConnectionFactory" 
        p:defaultDestination-ref="destination" />
    <!-- A JmsTemplate instance that uses the connection and destination end -->
    <!--Cofiguring JMS container and listener-->
    <jms:listener-container container-type="default" 
        connection-factory="cachedAmqConnectionFactory" destination-type="queue" >
        <jms:listener destination="APLIX.ERRORINFO" 
            ref="aplixSubscriberQueueService" method="onMessage" />
    </jms:listener-container>
    <!--Cofiguring JMS container and listener end-->
    <!-- The Spring message listener container configuration -->
    <amq:broker start="true" persistent="false" 
        brokerName="broker#{T(com.gehcit.cp.ws.ServiceProperties).instance().getProperty(T(com.gehcit.cp.Constants).CENTRICITY_DEPLOY_ID)}-applix" 
        deleteAllMessagesOnStartup="false" >
        <amq:managementContext>
            <amq:managementContext createConnector="false"/>
        </amq:managementContext>
        <amq:systemUsage>
            <amq:systemUsage>
                <amq:memoryUsage>
                    <amq:memoryUsage limit="512 mb"/>
                </amq:memoryUsage>
                <amq:tempUsage>
                    <amq:tempUsage limit="2 gb"/>
                </amq:tempUsage>
            </amq:systemUsage>
        </amq:systemUsage>      
        <amq:transportConnectors>
            <amq:transportConnector name="vm" 
                uri="vm://broker#{T(com.gehcit.cp.ws.ServiceProperties).instance().getProperty(T(com.gehcit.cp.Constants).CENTRICITY_DEPLOY_ID)}-applix"/>
        </amq:transportConnectors>
    </amq:broker>
</beans>

Can someone help me find a way to refer beans from other xml files in Spring 5.2.x.
Note: We have changed the classloading part with Spring 5.2.

Added this to the web.xml

    <listener-class>com.gehcit.cp.ws.infrastructure.security.BeanFactoryContextLoaderListener</listener-class>
</listener>
<!-- <context-param>
    <param-name>locatorFactorySelector</param-name>
    <param-value>/beanRefFactory.xml</param-value>
</context-param>  -->

BeanFactoryContextLoaderListener.java

package com.gehcit.cp.ws.infrastructure.security;
import javax.servlet.ServletContext;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
public class BeanFactoryContextLoaderListener extends ContextLoaderListener {
private static Logger log = Logger.getLogger(BeanFactoryContextLoaderListener.class)     
    @Override
        protected ApplicationContext loadParentContext(ServletContext servletContext) { 
         log.info("Entered loadParentContext");    
         ApplicationContext ctx = new ClassPathXmlApplicationContext("beanRefFactory.xml");
         log.info("Exit loadParentContext" + ctx.toString());
         return ctx;
        }
}

This has something to do with ApplicationContext which I am unable to resolve.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文