gpt4 book ai didi

java - Spring Boot - HttpMessageNotReadableException : JSON parse error: java.net.SocketTimeoutException

转载 作者:行者123 更新时间:2023-12-04 13:56:26 25 4
gpt4 key购买 nike

我的代码抛出异常如下

JSON parse error: java.net.SocketTimeoutException; nested exception is com.fasterxml.jackson.databind.JsonMappingException: java.net.SocketTimeoutException (through reference chain: java.util.ArrayList[9])
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: java.net.SocketTimeoutException; nested exception is com.fasterxml.jackson.databind.JsonMappingException: java.net.SocketTimeoutException (through reference chain: java.util.ArrayList[9])
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:245) ~[spring-web-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:227) ~[spring-web-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:204) ~[spring-webmvc-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:157) ~[spring-webmvc-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:130) ~[spring-webmvc-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:127) ~[spring-web-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:167) ~[spring-web-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134) ~[spring-web-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) ~[spring-webmvc-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:892) ~[spring-webmvc-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) ~[spring-webmvc-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1039) [spring-webmvc-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

我的spring-boot版本是2.1.7.RELEASE,使用内嵌的tomcat运行应用。
我还设置了属性 server.connection-timeout=30s
我几乎到处搜索,但无法确定此问题的根本原因。我也捕获此异常并将其打印在日志中,并将响应作为 BAD_REQUEST 返回。

这个异常是间歇性抛出的,我的生产服务器此时消耗了 80% 以上的 CPU 和内存。

这实际上是一个 POST 请求,请求正文验证如下
    @RequestMapping( value = "/save", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE )
public SaveDto create( @RequestBody @Valid SaveDto saveDto,
HttpServletResponse response, HttpServletRequest request )
{
//my logic
}

我的 SaveDto 如下
@JsonInclude( JsonInclude.Include.NON_NULL )
public class SaveDto
{
private String id;
@Size( min = 1 )
@Valid
private List< SaveEntryDto > saveLogEntries;
}

我的 saveEntryDto 如下
public class SaveEntryDto implements Comparable<SaveEntryDto> {
private String id;
private String idRef;
private WER wer;
@Min(0)
@Max(1440)
private Integer kjh;
@Min(0)
@Max(1440)
private Integer gfd;
private String abc;
private Double def;
private String ghi;
private Boolean klm = Boolean.FALSE;
private Boolean hug;
private Boolean qwe;
private Double azx;
private Double xds;
private Boolean cvf = Boolean.FALSE;
private Boolean bgh = Boolean.FALSE;
private String nmj;
private Boolean rgh;
private Boolean jkh;
private Boolean mkl = Boolean.FALSE;
private Boolean wed = Boolean.FALSE;
private Long ftu;
private XYZ xyzxd;
private String klp;
private ABC xxz;
private Boolean llo;
private Long iop;
private Double poi;
private Boolean uyt = Boolean.FALSE;
private Boolean rew = Boolean.FALSE;
private String qsd;
}

最佳答案

试试 server.tomcat.connection-timeout而不是 server.connection-timeout .出于某种原因,很多人提到了 server.connection-timeout ,但我认为它没有任何作用(根据 https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html )。server.tomcat.connection-timeout=30000 - 这将超时设置为 30 秒

关于java - Spring Boot - HttpMessageNotReadableException : JSON parse error: java.net.SocketTimeoutException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61459085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com