解决 postman测试接口报404 Not Found

JDK版本:jdk17

IDEA版本:IntelliJ IDEA 2022.1.3


文章目录


问题描述

当我使用postman测试接口时,报了 404 Not Found 的错误,报错截图如下所示

但我的后端程序中已经定义了该接口,如下所示

但postman始终无法找到这个接口!!!


原因分析

我百度了很久,一般来说,404错误基本上是接口路径,提交方式、参数类型、返回结果类型有误所致

然而我仔细核对了上述因素,均属正确!!!

这就非常奇怪了? 后来我突发奇想,找不到资源,也许不一定是上面的原因,很有可能存在多个重复的请求路径。

因为我的demo项目中使用了Spring Security框架,Spring Security框架默认使用 /logout该请求路径用于处理用户的登出操作。当用户请求/logout时,Spring Security会执行登出流程,这通常包括清除用户的认证信息、重定向到登出成功页面或登出后的URL!!!

源码如下

官方解释如下

Constructor which takes a LogoutSuccessHandler instance to determine the target destination after logging out. The list of LogoutHandlers are intended to perform the actual logout functionality (such as clearing the security context, invalidating the session, etc.).

翻译

构造函数,它在注销后使用LogoutSuccessHandler实例来确定目标目标。LogoutHandlers列表用于执行实际的注销功能(如清除安全上下文、使会话无效等)


解决方案

将自定义的请求路径/logout 重命名即可

重新测试如下

排错成功!!!


相关推荐
camellias_4 小时前
【无标题】
java·tomcat
咸鱼2.04 小时前
【java入门到放弃】需要背诵
java·开发语言
椰猫子4 小时前
Java:异常(exception)
java·开发语言
win x5 小时前
Redis 使用~如何在Java中连接使用redis
java·数据库·redis
星晨雪海5 小时前
基于 @Resource 的支付 Service 多实现类完整示例
java·开发语言
阿维的博客日记5 小时前
什么是逃逸分析
java·juc
Ricky_Theseus6 小时前
C++右值引用
java·开发语言·c++
Rick19936 小时前
Java内存参数解析
java·开发语言·jvm
我是大猴子6 小时前
Spring代理类为何依赖注入失效?
java·后端·spring
勿忘,瞬间6 小时前
多线程之进阶修炼
java·开发语言