解决 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 重命名即可

重新测试如下

排错成功!!!


相关推荐
wb043072011 小时前
性能优化实战:基于方法执行监控与AI调用链分析
java·人工智能·spring boot·语言模型·性能优化
天若有情6732 小时前
Java Swing 实战:从零打造经典黄金矿工游戏
java·后端·游戏·黄金矿工·swin
lichong9513 小时前
Android studio 修改包名
android·java·前端·ide·android studio·大前端·大前端++
lichong9513 小时前
Git 检出到HEAD 再修改提交commit 会消失解决方案
java·前端·git·python·github·大前端·大前端++
@yanyu6663 小时前
Tomcat安装与HTML响应实战
java·tomcat·html
Chen-Edward4 小时前
有了Spring为什么还有要Spring Boot?
java·spring boot·spring
magic334165635 小时前
Springboot整合MinIO文件服务(windows版本)
windows·spring boot·后端·minio·文件对象存储
胜天半月子5 小时前
性能测试 | 性能测试工具Jmeter的认识和基础使用
测试工具·jmeter·性能测试
陈小桔5 小时前
idea中重新加载所有maven项目失败,但maven compile成功
java·maven
小学鸡!5 小时前
Spring Boot实现日志链路追踪
java·spring boot·后端