@RequestBody没有在春季启动工作

问题描述 投票:0回答:1

您好我是新来的春天开机,已经发布采购信息问题

我收到以下错误

 2019-01-31 10:41:56.011  WARN 9532 --- [nio-8090-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: I/O error while reading input message; nested exception is java.net.SocketTimeoutException]

我使用的邮差用于测试目的

我有下面的代码片段

控制器:

@RestController
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    public EmployeeController() {}
    public EmployeeController(EmployeeService employeeService) {
        this.employeeService = employeeService;
    }

    @GetMapping("/employee")
    public List<Employee> getAllEmployee() {
        System.out.println("EmployeeController.getAllEmployee()");
        return this.employeeService.getAllEmployee();
    }

    @PostMapping(value="/employee")
    public Employee addEmployee( @RequestBody Employee employee ) {
        System.out.println("EmployeeController.addEmployee()");
        System.out.println(employee.toString());
//      this.employeeService.addEmployee( employee );
        return employee;
    }
}

实体类为:

@Entity
@Table(name="emp_table")
public class Employee  {

    private static final long serialVersionUID = 1L;
    @Id
    private Long id; 
    private String firstName;
    private String lastName;
    private String city;
    private Double salary;

    public Employee() {}
    public Employee(Long id, String firstName, String lastName, String city, Double salary) {
        this.id = id;
        this.firstName = firstName;
        this.lastName = lastName;
        this.city = city;
        this.salary = salary;
    }
    // Getters and Setters + toString()
}

邮差POST请求

enter image description here

从邮差响应堆栈跟踪

{
"timestamp": "2019-02-01T04:31:17.220+0000",
"status": 400,
"error": "Bad Request",
"message": "I/O error while reading input message; nested exception is java.net.SocketTimeoutException",
"trace": "org.springframework.http.converter.HttpMessageNotReadableException: I/O error while reading input message; nested exception is         java.net.SocketTimeoutException\r\n\tat 
org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:216)\r\n\tat 
org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:157)\r\n\tat 
org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:130)\r\n\tat 
org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:126)\r\n\tat 
org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:166)\r\n\tat 
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134)\r\n\tat 
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)\r\n\tat 
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)\r\n\tat 
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)\r\n\tat 
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)\r\n\tat 
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)\r\n\tat 
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)\r\n\tat 
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)\r\n\tat 
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)\r\n\tat 
javax.servlet.http.HttpServlet.service(HttpServlet.java:660)\r\n\tat 
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)\r\n\tat 
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)\r\n\tat 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)\r\n\tat 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat 
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)\r\n\tat 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat 
org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)\r\n\tat 
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\r\n\tat 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat 
org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)\r\n\tat 
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\r\n\tat 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat 
org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)\r\n\tat 
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\r\n\tat 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat 
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)\r\n\tat 
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\r\n\tat 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)\r\n\tat 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)\r\n\tat 
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)\r\n\tat 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)\r\n\tat 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)\r\n\tat 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)\r\n\tat 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)\r\n\tat 
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)\r\n\tat 
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)\r\n\tat 
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)\r\n\tat 
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)\r\n\tat 
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)\r\n\tat 
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)\r\n\tat 
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)\r\n\tat 
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)\r\n\tat 
java.lang.Thread.run(Unknown Source)\r\n Caused by:         java.net.SocketTimeoutException\r\n\tat 
        org.apache.tomcat.util.net.NioBlockingSelector.read(NioBlockingSelector.java:201)\r\n\tat 
org.apache.tomcat.util.net.NioSelectorPool.read(NioSelectorPool.java:222)\r\n\tat 
org.apache.tomcat.util.net.NioSelectorPool.read(NioSelectorPool.java:203)\r\n\tat 
org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1199)\r\n\tat 
org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1142)\r\n\tat 
org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:729)\r\n\tat 
org.apache.coyote.http11.Http11InputBuffer.access$300(Http11InputBuffer.java:40)\r\n\tat 
org.apache.coyote.http11.Http11InputBuffer$SocketInputBuffer.doRead(Http11InputBuffer.java:1061)\r\n\tat 
org.apache.coyote.http11.filters.IdentityInputFilter.doRead(IdentityInputFilter.java:102)\r\n\tat 
org.apache.coyote.http11.Http11InputBuffer.doRead(Http11InputBuffer.java:245)\r\n\tat 
org.apache.coyote.Request.doRead(Request.java:551)\r\n\tat 
org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:335)\r\n\tat 
org.apache.catalina.connector.InputBuffer.checkByteBufferEof(InputBuffer.java:628)\r\n\tat 
org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:358)\r\n\tat 
org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:132)\r\n\tat 
java.io.FilterInputStream.read(Unknown Source)\r\n\tat         
java.io.PushbackInputStream.read(Unknown Source)\r\n\tat 
com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.ensureLoaded(ByteSourceJsonBootstrapper.java:522)\r\n\tat 
com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.detectEncoding(ByteSourceJsonBootstrapper.java:129)\r\n\tat 
com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.constructParser(ByteSourceJsonBootstrapper.java:246)\r\n\tat 
com.fasterxml.jackson.core.JsonFactory._createParser(JsonFactory.java:1315)\r\n\tat 
com.fasterxml.jackson.core.JsonFactory.createParser(JsonFactory.java:820)\r\n\tat 
com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3084)\r\n\tat 
org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:239)\r\n\tat 
org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:227)\r\n\tat 
org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:204)\r\n\t... 53 more\r\n",
"path": "/employee"

}

spring spring-boot http-post postman jsonconvert
1个回答
0
投票

改变从邮差API测试工具高级REST客户端,然后将其worked.Don't知道为什么吗? 任何一个可以解释......?

热门问题
推荐问题
最新问题