java - 在 RestController 方法中获取 ServerWebExchange
问题描述
如何在控制器方法中获取ServerWebExchange
或响应?ServerHttpResponse
我NestedServletException
在尝试调用接受的休息控制器方法时不断得到ServerWebExchange
。
我的控制器如下所示:
@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);
}
}
例外:
io.undertow.request : UT005023: 对 /path/value/path/path 的异常处理请求
org.springframework.web.util.NestedServletException:请求处理失败;嵌套异常是 java.lang.IllegalStateException: No primary or default constructor found for interface org.springframework.web.server.ServerWebExchange
解决方案
解决方案:确保您spring-webmvc
在类路径上没有。
我正在迁移到spring-webflux
,但得到spring-webmvc
了传递依赖。webflux
并且webmvc
不兼容 - 只有一个会处理请求。
推荐阅读
- javascript - jQuery 调用 on() on() 在调用 click() 后动态生成它
- angular - Angular 12 材质垫抽屉自动隐藏
- amazon-web-services - 在不同账户中执行 Athena 查询后无法查看 S3 存储桶中的结果?
- itext - 使用 iText、PKCS11 和 SHA-256 算法签署 PDF 时出现问题
- ios - 快速解开多个选项
- swift - 在mac中通过corebluetooth扫描窗口PC
- swift - Swift - Alamofire 返回“无效的请求格式”。当我尝试将文件上传到 pinata
- uber-api - uber 吃掉 OAuth 2.0 授权得到 error.invalid_request
- remote-access - ESP8266 网络服务器关闭 win10 计算机
- flutter - 在 Flutter 中删除操作后更新列表项