- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Rest Controller 中使用 ServerHttpRequest 作为请求参数。但在响应中我收到错误“找不到接口(interface) org.springframework.http.server.reactive.ServerHttpRequest 的主要或默认构造函数”。
我找到了一个类似的question ,但没有运气。
休息 Controller
@GetMapping(path = "/**")public Mono <ResponseEntity< String>> clientRequests(ServerHttpRequest request) { Mono<ResponseEntity<String>> jsonOp = restServices.getApiResponse(); return jsonOp;}
日志
SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: No primary or default constructor found for interface org.springframework.http.server.reactive.ServerHttpRequest] with root causejava.lang.NoSuchMethodException: org.springframework.http.server.reactive.ServerHttpRequest.() at java.lang.Class.getConstructor0(Class.java:3082) at java.lang.Class.getDeclaredConstructor(Class.java:2178) at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:216) at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:84) at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:139) at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:126) at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:166) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:892) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897) at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
Pom.xml
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> <version>${spring-boot.version}</version> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>${spring-boot.version}</version> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.projectreactor.netty</groupId> <artifactId>reactor-netty</artifactId> <version>${reactor-netty.version}</version> </dependency> </dependencies>
版本:
<spring-boot.version>2.1.4.RELEASE</spring-boot.version> <reactor-netty.version>0.8.6.RELEASE</reactor-netty.version>
最佳答案
正如 @Brian Clozel 提到的,这可能是由于“Spring WebFlux”和“Spring MVC”框架的共存以及 Spring 在将应用程序配置为基于 servlet 的 Web 应用程序时的自动化行为造成的 ( here )。
因此,尝试将您的应用程序作为 REACTIVE Web 应用程序运行:
//以编程方式here
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(YourApp.class);
springApplication.setWebApplicationType(WebApplicationType.REACTIVE);
springApplication.run(args);
}
//按属性here
spring.main.web-application-type=REACTIVE
关于java - Spring Controller 不支持ServerHttpRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56320109/
Spring 启动:2.2.4 springdoc-openapi-ui:1.3.0 Java:11 项目编译并正确启动,导航到 /swagger-ui.html 时出现异常: java.lang.N
想要在 Spring API Gateway 之上实现代理来记录请求/响应。我为传入请求和传出响应定义了自己的过滤器。 请求网关过滤器: public class RequestGatewayFilt
我正在使用 spring boot 版本 - 2.0.6.RELEASE 和 spring cloud 版本 - Finchley.SR2 并且我已经创建了我的自定义网关过滤器来修改请求正文。 但是在
这个问题与 this one 非常相似。除了我使用的事实: org.springframework.http.server.ServerHttpRequest 不是 HttpServletReques
我有如下代码: MyExceptionHandler { @ExceptionHandler(Exception.class) public Object handleMvc(Exceptio
我有一个 Controller @RestController public class NameController { @Autowired private NameService
我是一名优秀的程序员,十分优秀!