Java Spring集成出站网关希望像动态网关一样使用URL

Java Spring集成出站网关希望像动态网关一样使用URL,java,spring,spring-integration,Java,Spring,Spring Integration,spring集成,在出站网关中要像动态一样使用URL <bean id="requestValues" class="com.src.model.RequestValues"/> <int-http:outbound-gateway request-channel="reqChannel" url="${UrlValue}" http-method="${reqmethod}" expecte

spring集成,在出站网关中要像动态一样使用URL

    <bean id="requestValues"    class="com.src.model.RequestValues"/>
    <int-http:outbound-gateway
                request-channel="reqChannel" url="${UrlValue}"
                http-method="${reqmethod}" expected-response-type="java.lang.String"  header-mapper="headerMapper"
                charset="UTF-8" reply-timeout="5000" reply-channel="responseChannel"  >
            <int-http:uri-variable name="UrlValue" expression="#{requestValues.getUrl()}" />
           <int-http:uri-variable name="reqmethod" expression="#{requestValues.getReqMethod()}" />
        </int-http:outbound-gateway>
org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler#0”的bean时出错:无法创建[org.springframework.integration.config.ExpressionFactoryBean]类型的内部bean'(内部bean)#6ea2bc93]使用键[url]设置bean属性“uriVariableExpressions”时;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“(内部bean)#6ea2bc93”的bean时出错:通过构造函数实例化bean失败;嵌套异常为org.springframework.beans.beans实例化异常:未能实例化[org.springframework.integration.config.ExpressionFactoryBean]:构造函数引发异常;嵌套异常为java.lang.IllegalArgumentException:expressionString不能为空或null


您可以将URL或http方法等元数据设置为标头。您甚至可以在设置收割台f.e.时使用弹簧EL

<int:header-enricher>
    <int:header name="url" value="${url.base}/reports/"/>
</int:header-enricher>

然后为出站网关使用表达式

 <int-http:outbound-gateway id='httpGateway'
 url-expression="headers['url']"
...
  />


http方法
不是URI的一部分;它不支持或使用
uri变量

改用http method expression=“payload.reqMethod”

类似地,
Accept
不是uri的一部分-在出站消息中设置Accept头,它将被映射

编辑

您将运行时表达式与bean声明表达式混淆,正如我所说的,如果您想要选择运行时方法,则需要使用方法表达式

但是,由于您将bean用于
Requestvalues
,因此根本不需要运行时表达式

<int-http:outbound-gateway
            request-channel="reqChannel" url="#{requestValues.getUrl()}"
            http-method=""#{requestValues.getReqMethod()}" expected-response-type="java.lang.String"  header-mapper="headerMapper"
            charset="UTF-8" reply-timeout="5000" reply-channel="responseChannel"  >
</int-http:outbound-gateway>

接受
方法
不属于URI的一部分,因此不能使用
URI变量
s。感谢您的回复,但此处的小更正接受和内容类型工作正常,唯一的目的是使URL成为动态的,我在java代码中根据特定条件创建的URL MMM感谢感谢您的回复请留下,这里我的疑问是如何使我的URL和http方法成为动态的,这必须来自POJOThanks,以供您的回复,但这里的小更正Accept&content type工作正常,唯一想使URL成为动态的,在特定条件下,我在java代码中创建的URL
-
接受
内容类型
头不是从
uri变量设置的;你必须在其他地方设置标题,可能是在转换器中。嗯,很好,格雷,现在我修改了我的问题,再次重复我的问题,希望将我的URL和http方法设置为genericYou正在混合运行时和初始化时表达式;查看我的编辑。这不是答案-请编辑您的问题。第一个似乎表明您的
requestValues
设置不正确;同样的事情(对于URL)对于第二个;您需要显示所有代码。
<int-http:outbound-gateway
            request-channel="reqChannel" url="#{requestValues.getUrl()}"
            http-method=""#{requestValues.getReqMethod()}" expected-response-type="java.lang.String"  header-mapper="headerMapper"
            charset="UTF-8" reply-timeout="5000" reply-channel="responseChannel"  >
</int-http:outbound-gateway>
<int-http:outbound-gateway
            request-channel="reqChannel" url="${UrlValue}"
            http-method-expression="headers['method']" expected-response-type="java.lang.String"  header-mapper="headerMapper"
            charset="UTF-8" reply-timeout="5000" reply-channel="responseChannel"  >
        <int-http:uri-variable name="UrlValue" expression="headers['url']" />
</int-http:outbound-gateway>
<int-http:outbound-gateway
            request-channel="reqChannel" url="${UrlValue}"
            http-method-expression="@requestValues.getReqMethod()" expected-response-type="java.lang.String"  header-mapper="headerMapper"
            charset="UTF-8" reply-timeout="5000" reply-channel="responseChannel"  >
        <int-http:uri-variable name="UrlValue" expression="@requestValues.getUrl()" />
</int-http:outbound-gateway>