{"record":{"id":"890468fc174fb343","repo":"xkcoding/spring-boot-demo","slug":"404-890468","errorCode":"404","errorMessage":"请求不存在！","messagePattern":"请求不存在！","errorType":"exception","errorClass":"SecurityException","httpStatus":null,"severity":"warning","filePath":"demo-rbac-security/README.md","lineNumber":544,"sourceCode":"        Multimap<String, String> urlMapping = allUrlMapping();\n\n        for (String uri : urlMapping.keySet()) {\n            // 通过 AntPathRequestMatcher 匹配 url\n            // 可以通过 2 种方式创建 AntPathRequestMatcher\n            // 1：new AntPathRequestMatcher(uri,method) 这种方式可以直接判断方法是否匹配，因为这里我们把 方法不匹配 自定义抛出，所以，我们使用第2种方式创建\n            // 2：new AntPathRequestMatcher(uri) 这种方式不校验请求方法，只校验请求路径\n            AntPathRequestMatcher antPathMatcher = new AntPathRequestMatcher(uri);\n            if (antPathMatcher.matches(request)) {\n                if (!urlMapping.get(uri)\n                        .contains(currentMethod)) {\n                    throw new SecurityException(Status.HTTP_BAD_METHOD);\n                } else {\n                    return;\n                }\n            }\n        }\n\n        throw new SecurityException(Status.REQUEST_NOT_FOUND);\n    }\n\n    /**\n     * 获取 所有URL Mapping，返回格式为{\"/test\":[\"GET\",\"POST\"],\"/sys\":[\"GET\",\"DELETE\"]}\n     *\n     * @return {@link ArrayListMultimap} 格式的 URL Mapping\n     */\n    private Multimap<String, String> allUrlMapping() {\n        Multimap<String, String> urlMapping = ArrayListMultimap.create();\n\n        // 获取url与类和方法的对应信息\n        Map<RequestMappingInfo, HandlerMethod> handlerMethods = mapping.getHandlerMethods();\n\n        handlerMethods.forEach((k, v) -> {\n            // 获取当前 key 下的获取所有URL\n            Set<String> url = k.getPatternsCondition()\n                    .getPatterns();\n            RequestMethodsRequestCondition method = k.getMethodsCondition();","sourceCodeStart":526,"sourceCodeEnd":562,"githubUrl":"https://github.com/xkcoding/spring-boot-demo/blob/87a142f9604c1a5365b4d24d22c2c11c26a9d5ab/demo-rbac-security/README.md#L526-L562","documentation":"If no registered URI pattern matches the request path at all, checkRequest throws SecurityException(Status.REQUEST_NOT_FOUND, code 404) at README:544 (impl RbacAuthorityService.java:112). This is the app's own 404 inside the security filter; Spring's NoHandlerFoundException maps to the same code via GlobalExceptionHandler (requires throw-exception-if-no-handler-found enabled).","triggerScenarios":"Request to a path with no @RequestMapping; a typo; a removed endpoint; a context-path mismatch.","commonSituations":"Stale client calling a removed route; wrong API base path; missing servlet context path in the client URL.","solutions":["Verify the path against the controller mappings","Correct the client base URL or context path","Register the route if it is supposed to exist"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"boolean mapped = mapping.getHandlerMethods().keySet().stream()\n    .anyMatch(info -> info.getPatternsCondition().getPatterns().contains(request.getRequestURI()));\nif (!mapped) { /* 404 - correct the path or register the route */ }","typeGuard":null,"tryCatchPattern":"try { authorityService.checkRequest(request); }\ncatch (SecurityException e) { if (Status.REQUEST_NOT_FOUND.getCode().equals(e.getCode())) { /* 404 */ } }","preventionTips":["Verify client paths against the controller mappings","Keep the client base URL and context path correct","Enable throw-exception-if-no-handler-found for consistent 404 handling"],"tags":["spring-security","http","not-found"],"backgroundTag":null,"analyzedSha":"87a142f9604c1a5365b4d24d22c2c11c26a9d5ab","analyzedAt":"2026-08-14T01:16:58.217Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}