在 RestController 方法中获取 ServerWebExchange

Getting ServerWebExchange in RestController method

如何在控制器方法中获得 ServerWebExchange 或响应式 ServerHttpResponse

我在尝试调用接受 ServerWebExchange.

的其余控制器方法时不断收到 NestedServletException

我的控制器看起来像这样:

@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: 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 作为传递依赖项。 webfluxwebmvc 不兼容 - 只有一个可以处理请求。