来自子上下文的 Spring 集成 http 端点不起作用



当我在根上下文中配置Http入站通道适配器时,它起作用了:

    <int-http:inbound-channel-adapter id="httpInbount" path="test" channel="ch.http.in" />
        <int:channel id="ch.http.in" />
        <int:service-activator input-channel="ch.http.in" output-channel="ch.aggr.obj" ref="httpToObjTransformer" method="transform"></int:service-activator>
        <bean id="httpToObjTransformer" class="com.nevexis.dcard.integration.transformer.HttpToObjTransformer" />
        <int:channel id="ch.aggr.obj">
            <int:queue />
        </int:channel>

但是当我从子上下文加载它时,它没有注册。

 <int:channel id="ch.aggr.obj">
                <int:queue />
            </int:channel>

在根上下文中,我加载

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:int-http="http://www.springframework.org/schema/integration/http"
    xsi:schemaLocation="http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <int-http:inbound-channel-adapter id="httpInbount" path="transaction" channel="ch.http.in" />
    <int:channel id="ch.http.in" />
    <int:service-activator input-channel="ch.http.in" output-channel="ch.aggr.obj" ref="httpToObjTransformer" method="transform"></int:service-activator>
    <bean id="httpToObjTransformer" class="com.nevexis.dcard.integration.transformer.HttpToObjTransformer" />
</beans>

作为儿童GenericXmlApplicationContext .

当子上下文被加载时,我可以看到

IntegrationRequestMappingHandlerMapping:197 - Mapped "{[/transaction],methods=[GET || POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public abstract void org.springframework.web.HttpRequestHandler.handleRequest(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws javax.servlet.ServletException,java.io.IOException
日志

,但http://localhost:8081/transaction不能映射

这是因为DispatcherServlet是在单独的子上下文中定义的,它没有看到IntegrationRequestMappingHandlerMapping bean。

任何子上下文都可以从它的ancestors中看到bean,但是不能从其他子上下文中看到bean,因为父上下文不能在你的子上下文中看到bean。

需要理解为什么要在子上下文中声明集成流。为什么<context:import>对你来说不够?

最新更新