Evgeni Dimitrov Evgeni Dimitrov - 2 months ago 14
Java Question

Spring Integration http endpoint from child context doesen't work

When I configure Http inbound channel adapter in the root context it works:

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


But when I load it from a child context it's not registered.

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


is in the root context and I load

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


as a child
GenericXmlApplicationContext
.

When the child context is laoded I can see

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


in the log, but
http://localhost:8081/transaction
can't be mapped.

Answer

That's because DispatcherServlet is defined in the separete child context and it doesn't see IntegrationRequestMappingHandlerMapping bean.

Any child context can see beans from its ancestors, but not from other child context as well as the parent context can't see bean in your children.

There is need to understand why you want declare integration flow in the child context. Why isn't <context:import> enough for you?

Comments