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

SpringBoot 2.0启用OAuth2(Basic+Password授权类型)遇类找不到错误

解决Spring Boot 2.0 + Spring Security 5.x中OAuth2LoginAuthenticationFilter找不到的问题

嘿,我之前搭Spring Security OAuth2环境的时候也踩过这个坑!

你遇到的OAuth2LoginAuthenticationFilter找不到的问题,核心原因是这个类并不在你当前引入的依赖里。在Spring Security 5.x + Spring Boot 2.0的组合中,这个过滤器属于Spring Security OAuth2 Client模块,而你现在只加了spring-security-oauth2-autoconfigure——它只是提供OAuth2相关的自动配置类,并没有包含实际的OAuth2登录核心实现类。

给你几个具体的解决步骤:

  • 首先确认版本兼容性:Spring Boot 2.0.x和Spring Security 5.0.x的版本匹配是没问题的,但建议保持版本号统一,避免出现依赖冲突。
  • 添加缺失的核心依赖,在你的pom.xml中加入以下内容:
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-oauth2-client</artifactId>
</dependency>
  • 最后清理构建缓存并重新构建项目,比如执行Maven命令:mvn clean install -U,确保新依赖能正确下载并被项目识别。

另外补充一点:如果你是要搭建完整的OAuth2授权服务器,后续可能还需要引入spring-security-oauth2-authorization-server相关依赖,但当前解决这个类找不到的问题,先添加上面的依赖即可。

内容的提问来源于stack exchange,提问作者Isuru Samaraweera

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 08:57:47