You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular 18拦截器未激活且无法设置请求头的问题求助

Angular 18拦截器未激活且无法设置请求头的问题求助

各位大佬好,我最近在Angular 18项目里栽了个跟头——配置的请求拦截器完全没起作用,导致后端接口一直因为缺少正确的Authorization头把我拒之门外,快愁死了😅

后端返回的错误日志如下:

Pre-authenticated entry point called. Rejecting access
2024-09-29T12:39:52.861+02:00 DEBUG 14733 --- [nio-8080-exec-4] o.s.security.web.FilterChainProxy        : Securing GET /error
2024-09-29T12:39:52.861+02:00 DEBUG 14733 --- [nio-8080-exec-4] o.s.s.w.a.AnonymousAuthenticationFilter  : Set SecurityContextHolder to anonymous SecurityContext
2024-09-29T12:39:52.861+02:00 DEBUG 14733 --- [nio-8080-exec-4] o.s.s.w.a.Http403ForbiddenEntryPoint     : Pre-authenticated entry point called. Rejecting access
2024-09-29T12:39:53.031+02:00 DEBUG 14733 --- [nio-8080-exec-5] o.s.security.web.FilterChainProxy        : Securing GET /posts/all
2024-09-29T12:39:53.046+02:00  WARN 14733 --- [nio-8080-exec-5] c.antonsteve96.ngrx.security.JwtFilter   : Authorization header missing or does not start with 'Bearer '
2024-09-29T12:39:53.046+02:00 DEBUG 14733 --- [nio-8080-exec-5] o.s.s.w.a.AnonymousAuthenticationFilter  : Set SecurityContextHolder to anonymous SecurityContext
2024-09-29T12:39:53.046+02:00 DEBUG 14733 --- [nio-8080-exec-5] o.s.s.w.a.Http403ForbiddenEntryPoint     : Pre-authenticated entry point called. Rejecting access

从日志里能清楚看到,当我请求/posts/all接口时,后端明确抛出了警告:Authorization header missing or does not start with 'Bearer '。但我明明在拦截器里写了逻辑,要给所有请求自动加上带Bearer Token的Authorization头。

我已经对照Angular 18的官方文档检查了拦截器的注册方式,按要求配置了providers,但看起来拦截器根本就没被触发过。有没有朋友遇到过类似的问题?或者能帮我排查下可能的原因?比如是不是Angular 18的拦截器注册机制有什么新变化?或者我的拦截器代码里有什么容易忽略的细节坑?

备注:内容来源于stack exchange,提问作者Stefano Antonetti

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 15:38:01