Spring 集成 Java DSL:Http.outboundGateway 与 HttpMethod.PATCH 不工作

Spring Integration Java DSL: The Http.outboundGateway with the HttpMethod.PATCH is not working

当 Spring 集成使用 HttpMethod.PATCH 操作调用 Http.outboundGateway 时出现异常:

Caused by: java.net.ProtocolException: Invalid HTTP method: PATCH
at java.base/java.net.HttpURLConnection.setRequestMethod(HttpURLConnection.java:487)
at java.base/sun.net.www.protocol.http.HttpURLConnection.setRequestMethod(HttpURLConnection.java:569)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.setRequestMethod(HttpsURLConnectionImpl.java:365)
at org.springframework.http.client.SimpleClientHttpRequestFactory.prepareConnection(SimpleClientHttpRequestFactory.java:226)
at org.springframework.http.client.SimpleClientHttpRequestFactory.createRequest(SimpleClientHttpRequestFactory.java:146)
at org.springframework.http.client.support.HttpAccessor.createRequest(HttpAccessor.java:87)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:719)

这是JavaclassHttpURLConnection的问题,因为它不支持PATCH操作

我必须使用PATCH方法。处理这种情况的最佳方法是什么?

RestTemplate默认使用基于JavaHttpURLConnectionSimpleClientHttpRequestFactory。考虑使用其他一些 ClientHttpRequestFactory,例如HttpComponentsClientHttpRequestFactory。当您声明这样一个 bean 时,您可以将其注入 Http.outboundGateway().requestFactory():

/**
 * Set the {@link ClientHttpRequestFactory} for the underlying {@link RestTemplate}.
 * @param requestFactory The request factory.
 * @return the spec
 */
public HttpMessageHandlerSpec requestFactory(ClientHttpRequestFactory requestFactory) {