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

Spring Boot 2 OAuth2单点登录项目缺失指定类求Maven依赖

解决Spring Boot 2中OAuth2LoginAuthenticationFilter找不到的问题

嘿,我之前也踩过这个坑!org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter这个类属于Spring Security OAuth2 Client核心模块,你之前的依赖组合大概率没覆盖到它。

正确的Maven依赖配置

最省心的方式是直接用Spring Boot官方的starter依赖,它会自动帮你管理所有相关依赖的版本兼容性,不用手动纠结版本匹配:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>

如果因为特殊需求必须单独指定依赖版本(不推荐,除非你明确知道版本对应关系),可以这样配置:

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-oauth2-client</artifactId>
    <!-- 注意:版本要和你的Spring Boot 2版本匹配,比如Spring Boot 2.7.x对应Spring Security 5.7.x系列 -->
    <version>5.7.11</version>
</dependency>

额外排查小技巧

  • 检查你的spring-boot-starter-parent版本:确保是2.x系列,starter依赖会自动匹配对应的Spring Security OAuth2版本,避免版本冲突。
  • 确认pom.xml里没有意外排除spring-security-oauth2-client相关依赖。
  • 执行mvn clean install清理本地仓库缓存,有时候依赖下载不完整也会导致类找不到的问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 08:00:24