[英]Spring Rest Template Client : Connection to http://localhost:8080 refused
[英]Spring Rest Template Http client error exception
RestTemplate可以與內部url一起正常工作,但不能與公共url一起工作。
@Bean
public RestTemplate restTemplate() {
RestTemplate restTemplate = new RestTemplate();
setTimeout(restTemplate , 40000 , 40000);
return restTemplate;
}
private void setTimeout(RestTemplate restTemplate, int readTimeOut , int connectionTimeOut) {
restTemplate.setRequestFactory(new SimpleClientHttpRequestFactory());
SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
rf.setReadTimeout(readTimeOut);
rf.setConnectTimeout(connectionTimeOut);
}
有什么辦法可以解決此問題?
訪問公共URL時,它會由restteamplate拋出Httpclientexception。
org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request
17:24:46,913 INFO [stdout] (default task-1) at org.springframework.web.client.HttpClientErrorException.create(HttpClientErrorException.java:79) ~[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,913 INFO [stdout] (default task-1) at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:122) ~[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,913 INFO [stdout] (default task-1) at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:102) ~[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,913 INFO [stdout] (default task-1) at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63) ~[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,914 INFO [stdout] (default task-1) at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:777) ~[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,914 INFO [stdout] (default task-1) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:735) ~[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,914 INFO [stdout] (default task-1) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:669) ~[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,914 INFO [stdout] (default task-1) at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:578) ~[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,914 INFO [stdout] (default task-1) at com.epic.edbs.ib.serviceclient.RestClient.processRestCall(RestClient.java:46) ~[IB-1.00.jar:?]
17:24:46,915 INFO [stdout] (default task-1) at com.epic.edbs.ib.serviceclient.EswitchClient.processRequest(EswitchClient.java:92) ~[IB-1.00.jar:?]
17:24:46,915 INFO [stdout] (default task-1) at com.epic.edbs.ib_rest.servicekeyexchange.impl.ServiceKeyExchangeImpl.getUserKey(ServiceKeyExchangeImpl.java:79) ~[classes:?]
17:24:46,915 INFO [stdout] (default task-1) at com.epic.edbs.ib_rest.servicekeyexchange.impl.ServiceKeyExchangeImpl.getUserExchangeKey(ServiceKeyExchangeImpl.java:49) ~[classes:?]
17:24:46,916 INFO [stdout] (default task-1) at com.epic.edbs.ib_rest.servicekeyexchange.impl.ServiceKeyExchangeImpl$$FastClassBySpringCGLIB$$df1e3370.invoke(<generated>) ~[classes:?]
17:24:46,916 INFO [stdout] (default task-1) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,916 INFO [stdout] (default task-1) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,916 INFO [stdout] (default task-1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,916 INFO [stdout] (default task-1) at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:55) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,916 INFO [stdout] (default task-1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,916 INFO [stdout] (default task-1) at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:56) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,917 INFO [stdout] (default task-1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,917 INFO [stdout] (default task-1) at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:55) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
17:24:46,919 INFO [stdout] (default task-1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) ~[spring-aop-5.1.3.RELEASE.jar:5.1.3.RELEASE]
最后,我在下面的網址中找到了答案。
我錯過了請求bean中的@JsonIgnoreProperties(ignoreUnknown = true)
批注。
https://www.oipapio.com/question-9416560
非常感謝您的巨大貢獻。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.