我怎样才能得到ServerWebExchange
或响应式(Reactive) ServerHttpResponse
在 Controller 方法中?
我不断收到 NestedServletException
在尝试调用接受 ServerWebExchange
的其余 Controller 方法时.
我的 Controller 看起来像这样:
@RestController
@RequestMapping(path = "/path/{param1}/path", produces = MediaType.APPLICATION_JSON_VALUE)
public class MyController {
@GetMapping("/path")
public Mono<Void> method(ServerWebExchange exchange) {
...
}
}
主要方法:
@SpringBootApplication
@ComponentScan(basePackages = {"my.package1", "my.package2"})
@EnableWebFlux
public class MyApp {
public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);
}
}
异常(exception):
io.undertow.request : UT005023: Exception handling request to /path/value/path/path
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: No primary or default constructor found for interface org.springframework.web.server.ServerWebExchange
最佳答案
解决方案:确保您没有 spring-webmvc
在类路径上。
我正在迁移到 spring-webflux
,但得到了 spring-webmvc
作为传递依赖。 webflux
和 webmvc
不兼容 - 只有一个会处理请求。
关于java - 在 RestController 方法中获取 ServerWebExchange,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51349431/