我在 spring 集成 dsl 中找不到将 header 添加到 outboundGateway 的函数。
.handle(outboundGateway("localhost:8080/search")
.httpMethod(HttpMethod.GET)
.expectedResponseType(Order.class))
我想添加到请求中的 header 是
HttpHeaders headers = new HttpHeaders();
headers.setAccept(newArrayList(APPLICATION_JSON));
headers.setContentType(APPLICATION_JSON);
headers.add("Client-Id", "test");
谁能帮帮我
最佳答案
没错:Spring Integration 不允许直接操作HttpHeaders
对象。相反,您应该遵循规范的消息传递方法 - 无协议(protocol) .enrichHeaders()
:
.enrichHeaders(e -> e
.header(DefaultHttpHeaderMapper.ACCEPT, APPLICATION_JSON)
.header(DefaultHttpHeaderMapper.CONTENT_TYPE, APPLICATION_JSON)
.header("Client-Id", "test"))
.handle(outboundGateway("localhost:8080/search")
.httpMethod(HttpMethod.GET)
.expectedResponseType(Order.class))
关于spring-integration - 如何将请求 header 添加到 outboundGateway spring 集成 dsl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50176296/