No primary or default constructor found for interface ServerHttpRequest问题

部署运行你感兴趣的模型镜像

项目场景:


问题描述:

POST 请求时,抛出异常:

No primary or default constructor found for interface org.springframework.http.server.reactive.ServerHttpRequest

原因分析:

以下内容摘自:stackoverflow
链接: https://stackoverflow.com/questions/53615945/spring-webflux-annotated-rest-controller-doesnt-support-serverhttprequest-as-me.

The Spring Boot reference documentation says that deploying Spring WebFlux application as WARs is not a supported use case.

Spring Boot 参考文档说,将 Spring WebFlux 应用程序部署为 war 不是一个受支持的用例。

Also, the stacktrace in your question shows that you’re actually running a Spring MVC application, and Spring MVC doesn’t support org.springframework.http.server.reactive.ServerHttpRequest as a handler argument. Something in your build must be bringing Spring MVC.

此外,你问题中的 stacktrace 显示你实际上运行的是一个 Spring MVC 应用程序,而 Spring MVC 不支持 org.springframework.http.server.reactive。作为处理程序参数。你的构建中一定有什么东西带来了 springmvc。

When both WebFlux and MVC are present, Spring Boot will configure automatically your app as a Spring MVC app.

当 WebFlux 和 MVC 都存在时,Spring Boot 会自动将你的应用配置为 Spring MVC 应用。


解决方案:

1、用WebFlux时,获取请求头的信息时使用:ServerHttpRequest

2、用MVC时(或WebFlux、MVC依赖同时存在时),获取http请求头的信息使用:HttpServletRequest

您可能感兴趣的与本文相关的镜像

FLUX.1-dev

FLUX.1-dev

图片生成
FLUX

FLUX.1-dev 是一个由 Black Forest Labs 创立的开源 AI 图像生成模型版本,它以其高质量和类似照片的真实感而闻名,并且比其他模型更有效率

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值