0

using java 11 in my spring web mvc application and want to use "org.springframework.http.server.ServerHttpRequest" instead of "javax.servlet.http.HttpServletRequest" in my application as "ServerHttpRequest" is provided by spring. Usage of the same is provided in code snippet

`@ApiOperation(value = "sample text"")
  @ApiResponses(
      value = {
        @ApiResponse(
            code = 200,
            message = "Successful retrieval",
            response = SampleResponse.class)
      })
  @PostMapping(
      consumes = MediaType.APPLICATION_JSON_VALUE,
      produces = MediaType.APPLICATION_JSON_VALUE)
  public DeferredResult<SampleResponse> create(
      @RequestBody RequestBodyDO requestBodyDo, ServerHttpRequest request)`

When i am hitting the api, getting the following error. Can some one help here?

{"timestamp":"2023-08-31 14:09:08,276","message":" Servlet.service() for servlet [dispatcherServlet] in context with path [api] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: No primary or single public constructor found for interface org.springframework.http.server.ServerHttpRequest - and no default constructor found either] with root cause","logger":"org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/api].[dispatcherServlet]","level":"ERROR","thread":"http-nio-8080-exec-1","stack_trace":"j.l.IllegalStateException: No primary or single public constructor found for interface org.springframework.http.server.ServerHttpRequest - and no default constructor found either
\n\tat o.s.beans.BeanUtils.getResolvableConstructor(BeanUtils.java:250)
\n\tat o.s.w.m.a.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:216)
\n\tat o.s.w.s.m.m.a.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:85)
\n\tat o.s.w.m.a.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:144)
\n\tat o.s.w.m.s.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121)
\n\tat o.s.w.m.s.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:170)
\n\tat o.s.w.m.s.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
\n\tat o.s.w.s.m.m.a.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)
\n\tat o.s.w.s.m.m.a.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:894)
\n\tat o.s.w.s.m.m.a.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
\n\tat o.s.w.s.m.m.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
\n\tat o.s.w.s.DispatcherServlet.doDispatch(DispatcherServlet.java:1063)
\n\tat o.s.w.s.DispatcherServlet.doService(DispatcherServlet.java:963)
\n\tat o.s.w.s.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
\n\tat o.s.w.s.FrameworkServlet.doPost(FrameworkServlet.java:909)
\n\tat j.s.http.HttpServlet.service(HttpServlet.java:652)
\n\tat o.s.w.s.FrameworkServlet.service(FrameworkServlet.java:883)
\n\tat j.s.http.HttpServlet.service(HttpServlet.java:733)
\n\tat o.a.c.c.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
\n\tat o.a.c.c.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
\n\tat o.a.t.w.s.WsFilter.doFilter(WsFilter.java:53)
\n\tat o.a.c.c.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
\n\tat o.a.c.c.ApplicationFilterChain....\n"}

Have not found much resources in the net regarding the same

  • i think it will help you [spring-controller-is-not-supporting-serverhttprequest](https://stackoverflow.com/questions/56320109/spring-controller-is-not-supporting-serverhttprequest). – Andrei Lisa Sep 01 '23 at 15:18

0 Answers0