spring 集成 http 出站适配器未解析属性
spring integration http outbound adapter not resolving properties
我们正在使用 http 出站适配器发出 http get 请求,我们希望在属性文件从 envt 更改为 envt 时读取 URL。我们还使用消息负载向此 url 附加了一些其他路径,但随后它给了我们这个错误消息 "Caused by: java.lang.IllegalArgumentException: Map has no value for URL"。我们所需要的只是从属性文件中读取基础 url 并生成带有有效负载的最终 url。
这是我们的示例配置
<int-http:outbound-gateway request-channel="requestChannel"
url="${url}/{payload}"
http-method="GET"
expected-response-type="java.lang.String"
>
</int-http:outbound-gateway>
实际上 URL 中的 {payload}
是一个 URI 变量,它无法自动解析。看看它是如何工作的:
UriComponentsBuilder.fromUriString(uri).buildAndExpand(uriVariables)
其中 uriVariables
是那些 URI 变量的 Map
。
因此,在您的情况下,预期的配置必须是这样的:
<int-http:outbound-gateway request-channel="requestChannel"
url="${url}/{payload}"
http-method="GET"
expected-response-type="java.lang.String">
<int-http:uri-variable name="payload" expression="payload"/>
</int-http:outbound-gateway>
您可以在 Reference Manual 中找到更多信息。
我们正在使用 http 出站适配器发出 http get 请求,我们希望在属性文件从 envt 更改为 envt 时读取 URL。我们还使用消息负载向此 url 附加了一些其他路径,但随后它给了我们这个错误消息 "Caused by: java.lang.IllegalArgumentException: Map has no value for URL"。我们所需要的只是从属性文件中读取基础 url 并生成带有有效负载的最终 url。
这是我们的示例配置
<int-http:outbound-gateway request-channel="requestChannel"
url="${url}/{payload}"
http-method="GET"
expected-response-type="java.lang.String"
>
</int-http:outbound-gateway>
实际上 URL 中的 {payload}
是一个 URI 变量,它无法自动解析。看看它是如何工作的:
UriComponentsBuilder.fromUriString(uri).buildAndExpand(uriVariables)
其中 uriVariables
是那些 URI 变量的 Map
。
因此,在您的情况下,预期的配置必须是这样的:
<int-http:outbound-gateway request-channel="requestChannel"
url="${url}/{payload}"
http-method="GET"
expected-response-type="java.lang.String">
<int-http:uri-variable name="payload" expression="payload"/>
</int-http:outbound-gateway>
您可以在 Reference Manual 中找到更多信息。