我在项目中使用spring集成。以下是加载所需配置文件的web.xml代码:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:TestService/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>SpringDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value/>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpringDispatcherServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
这是我的applicationContext.xml
文件:
<int:annotation-config/>
<context:component-scan base-package="com.test"/>
<mvc:annotation-driven />
<import resource="JobDesigner-springintegration.xml"/>
<import resource="DataSourceConfiguration.xml"/>
<!-- Inbound/Outbound Channels -->
<int:channel id="httpJobRequest" />
<int:channel id="httpJobResponse" />
<int-http:inbound-gateway id="inboundhttpJobRequestGateway"
supported-methods="GET, POST"
request-channel="httpJobRequest"
reply-channel="httpJobResponse"
path="/jobdesigner"
reply-timeout="90000"
error-channel="cs-exceptionHandlingChannel" >
<int-http:header name="${headerNames.jobName}" expression="#requestParams.src[0]"/>
</int-http:inbound-gateway>
<!-- Http Rest Input Buffered Channel -->
<int:bridge input-channel="httpJobRequest" output-channel = "jobDesignerInputChannel" />
</beans>
这是我的JobDesigner-springintegration.xml
文件,该文件加载了所有具有spring集成通道的文件。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:int-xml="http://www.springframework.org/schema/integration/xml"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:int-http="http://www.springframework.org/schema/integration/http"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/xml
http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/integration/jdbc
http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
http://www.springframework.org/schema/integration/http
http://www.springframework.org/schema/integration/http/spring-integration-http.xsd ">
<import resource="spring-integration/Jobs/*.xml"/>
<!-- map of namespace prefix to URI -->
<util:map id="xmlMessageNamespace">
<entry key="SOAP" value="http://schemas.xmlsoap.org/soap/envelope/" />
</util:map>
<bean id="customerServProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:TestService/property-files/*.properties</value>
</list>
</property>
</bean>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:TestService/property-files/*.properties</value>
</list>
</property>
</bean>
<int:channel id="jobDesignerInputChannel" />
<int:channel id="cs-exceptionHandlingChannel" />
<bean id="msgHandler" class="com.org.cs.test.jobs.PQMessageHandler" />
<bean id="headerMapper" class="org.springframework.integration.http.support.DefaultHttpHeaderMapper">
<property name="inboundHeaderNames" value="*" />
<property name="outboundHeaderNames" value="HTTP_REQUEST_HEADERS, Use-200-on-204-response" />
<property name="userDefinedHeaderPrefix" value="" />
</bean>
<int:payload-type-router input-channel="jobDesignerInputChannel" default-output-channel="xmlMessageChannel">
<int:mapping type="java.util.HashMap" channel="multipartMessageChannel" />
</int:payload-type-router>
<int:chain input-channel="xmlMessageChannel" >
<int:service-activator ref="msgHandler" method="test" />
<int-xml:xpath-header-enricher default-overwrite="true" should-skip-nulls="true" >
<int-xml:header name="${headerNames.legacySystem}" xpath-expression="//LegacySystem" evaluation-type="STRING_RESULT" overwrite="true" />
</int-xml:xpath-header-enricher>
<int:header-enricher>
<int:header name="${headerNames.businessArea}" expression="#xpath(payload, '//businessArea/Code', 'boolean') ? null : #xpath(payload, '//businessArea')"/>
</int:header-enricher>
<int:router expression="${routing.jobChannel}"/>
</int:chain>
<int:chain input-channel="multipartMessageChannel" >
<int:router expression="${routing.jobChannel}"/>
</int:chain>
<int:chain input-channel="cs-exceptionHandlingChannel">
<!-- Service Activator to handle the errors -->
<int:service-activator ref="msgHandler" method="handleError" />
<!-- Router to routing the error messages to appropriate job channel for xsl transormation -->
<int:router expression="${routing.jobErrorChannel}"/>
</int:chain>
</beans>
以下属性是从属性文件中加载的:
routing.jobChannel=headers.jobDesignerJobName+'-InputChannel'
routing.jobErrorChannel=headers.jobDesignerJobName+'-XsltTransformInputChannel'
这个想法是根据"headers.jobDesignerJobName"
的值将消息路由到适当的通道。在访问我们应用程序的主页后,将所有通道部署到Jboss服务器中就可以成功访问它们。但是,奇怪的是,如果我们直接尝试使用http请求调用该通道,则无法访问任何通道。通过调试日志消息,我发现消息到达<int:service-activator ref="msgHandler" method="test" />
为止,但是此后它无法触发headers.jobDesignerJobName+'InputChannel'
,尽管headers.jobDesignerJobName
具有有效值。刚收到错误:no reply received within timeout
我的test()方法只是为调试目的而添加的虚拟方法:
public Message<?> test(Message<?> inMessage){
return inMessage;
}
这是怎么回事?
与JBOSS会话管理有关吗?在这种情况下,根据我的理解,applicationContext.xml
文件完全不可访问。有人可以告诉原因吗?
我们正在使用Maven进行依赖项管理。SpringIntegration会暂时传递Spring Messaging jar。
+- org.springframework.integration:spring-integration-core:jar:5.0.6.RELEASE:compile
[INFO] | +- org.springframework:spring-core:jar:5.0.6.RELEASE:compile
[INFO] | | \- org.springframework:spring-jcl:jar:5.0.6.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:5.0.6.RELEASE:compile
[INFO] | +- org.springframework:spring-context:jar:5.0.6.RELEASE:compile
[INFO] | +- org.springframework:spring-messaging:jar:5.0.6.RELEASE:compile
[INFO] | +- org.springframework:spring-tx:jar:5.0.6.RELEASE:compile
[INFO] | +- org.springframework.retry:spring-retry:jar:1.2.2.RELEASE:compile
[INFO] | \- io.projectreactor:reactor-core:jar:3.1.6.RELEASE:compile
[INFO] | \- org.reactivestreams:reactive-streams:jar:1.0.2:compile
还有其他想法吗?
答案 0 :(得分:1)
您确定您的msgHandler.test
方法返回什么吗?如果它是void
或返回null
,则流程停止,并且确实不会发生任何答复。因此,<int-http:inbound-gateway>
失败并出现上述错误。
您没有显示重要的代码,例如谁订阅了jobDesignerInputChannel
。谁向httpJobResponse
发送消息。 msgHandler.test
等。所有与问题真正相关的东西。但是您显示的是标准web.xml
。请问与问题有什么关系?
更新
很难理解您如此定制的配置中发生了什么。
我建议您启用<message-history>
并通过<wire-tap>
记录所有流量。因此,您将在日志中看到消息如何传递组件以及真正存在问题的地方。
有关更多信息,请参阅文档:
https://docs.spring.io/spring-integration/reference/html/#message-history
https://docs.spring.io/spring-integration/reference/html/#channel-wiretap