Spring集成:int-http:inbound-gateway没有路径变量集

时间:2017-02-17 11:54:38

标签: spring-mvc spring-integration

我正在使用Spring Integration(版本4.3.1)int-http:inbound-gateway,我发现#pathVariables没有设置。

<int-http:inbound-gateway id="httpInboundGatewayPathAdapterControlBus" 
                      request-channel="controlBusIn" 
                      reply-channel="controlBusWithReplyChannel"
                      supported-methods="GET"
                      path="{pathvalue}" request-payload-type="java.lang.String" 
                      payload-expression="#pathVariables.pathvalue">

我的web.xml

<listener>
  <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

<servlet>
  <servlet-name>httpInboundGatewayPathAdapterControlBus</servlet-name>  
  <servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
</servlet>

<servlet-mapping>
  <servlet-name>httpInboundGatewayPathAdapterControlBus</servlet-name>
  <url-pattern>/controlBusURIExpression/*</url-pattern>
</servlet-mapping>

调试似乎表明spring的HttpRequestHandlingEndpointSupport在下面找不到任何设置URI_TEMPLATE_VARIABLES_ATTRIBUTE: -

Map<String, String> pathVariables =
            (Map<String, String>) servletRequest.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);

我也尝试添加

<bean id="integrationRequestMappingHandlerMapping" class="org.springframework.integration.http.inbound.IntegrationRequestMappingHandlerMapping"/>

但仍然得到一个Exception,我认为因为没有添加路径变量,而stacktrace表明没有使用IntegrationRequestMappingHandlerMapping。

非常感谢任何帮助。

    2017-02-17 11:26:03.223:WARN:oejs.ServletHandler:qtp2505735-16: /xxxxxxxxx-integration-app/controlBusURIExpression/controlBus/getCreateCheckCaseCurrentConsumers
org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Property or field 'pathvalue' cannot be found on null
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:220)
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:94)
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:46)
        at org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:374)
        at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88)
        at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:120)
        at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:242)
        at org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport.actualDoHandleRequest(HttpRequestHandlingEndpointSupport.java:463)
        at org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport.doHandleRequest(HttpRequestHandlingEndpointSupport.java:399)
        at org.springframework.integration.http.inbound.HttpRequestHandlingMessagingGateway.handleRequest(HttpRequestHandlingMessagingGateway.java:103)
        at org.springframework.web.context.support.HttpRequestHandlerServlet.service(HttpRequestHandlerServlet.java:67)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:806)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)

1 个答案:

答案 0 :(得分:0)

我刚尝试使用http sample app,将入站网关更改为

<int-http:inbound-gateway request-channel="receiveChannel"
                      path="{pathValue}"
                      payload-expression="#pathVariables.pathValue"
                      supported-methods="GET"/>

它对我来说很好:

enter image description here

我只能通过错误输入变量名来获得该错误。

你的web.xml应该是这样的......

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>http</display-name>
  <servlet>
    <servlet-name>SI</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/servlet-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>SI</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>