java - Spring集成出站网关想要使用动态URL

标签 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}" 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>

这里Requestvalues是简单的POJO 它就像

@Data
public class Requestvalues {

    public String Url;
    public String reqMethod;

}

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler#0': Cannot create inner bean '(inner bean)#6ea2bc93' of type [org.springframework.integration.config.ExpressionFactoryBean] while setting bean property 'uriVariableExpressions' with key [url]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#6ea2bc93': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.config.ExpressionFactoryBean]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: expressionString must not be empty or null

最佳答案

您可以将 URL 或 http 方法等元数据设置为 header 。您甚至可以在设置 header 时使用 Spring 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']"
...
  />

关于java - Spring集成出站网关想要使用动态URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46540067/

相关文章:

java - 在我的 REST Web 服务的服务层中使用 @EJB 或 @Inject 注入(inject) EJB?

java - 为什么 Stream::reduce 中的累加器是 BiFunction 而不是像组合器那样的 BinaryOperator?

java - Hibernate schema 生成 : same configurations, 不同行为

java - 为什么 Eclipse 不编译我的 Web 应用程序?

java - Hibernate 5 插入后更新

java - 使用 XPath 时有没有办法避免 Jaxp13XPathExpression 的瓶颈?

java - 如何从 JSON 的子级获取数据

JavaFX 场景中的 Java Processing 3 PAplet 作为 FXNode

java - Spring Integration - 将 IntegrationManagementConfigurer 与服务激活器结合使用

int-jms :outbound-channel-adapter from spring integration 的 Java 配置