HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
在调试程序中发现右边,
((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();是来自javax.servlet.http.HttpServletRequest;
而与左边
HttpServletRequest request来自jakarta.servlet.http.HttpServletRequest;不匹配
解决方法:
更新依赖spring web依赖就成功解决。
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>6.0.15</version>
</dependency>
但凡不匹配,找不到类等问题都来自于版本问题,同学们可以查阅版本