当Spring Integration使用Http.outboundGateway
操作进行HttpMethod.PATCH
调用时,会出现以下异常:
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)
这是Java类HttpURLConnection
中的问题,因为它不支持PATCH操作。
我必须使用PATCH
方法。处理这种情况的最佳方法是什么?
答案 0 :(得分:2)
RestTemplate
默认使用基于Java SimpleClientHttpRequestFactory
的{{1}}。考虑使用其他一些HttpURLConnection
,例如ClientHttpRequestFactory
。声明此类bean时,可以将其注入HttpComponentsClientHttpRequestFactory
:
Http.outboundGateway().requestFactory()