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

Spring Authorization Server项目报错NoClassDefFoundError求助

解决NoClassDefFoundError: SecurityContextHolderFilter问题

问题根源

org.springframework.security.web.context.SecurityContextHolderFilter是Spring Security 5.7及以上版本新增的组件,你当前使用的Spring Security 5.6.9版本中并不包含这个类。而Spring Authorization Server 0.4.0对Spring Security的版本要求高于5.6.9,两者版本不匹配导致依赖冲突,最终触发类找不到的错误。

修复方案

1. 升级Spring Boot版本(推荐)

Spring Authorization Server 0.4.0需要搭配Spring Boot 2.7.x或更高版本使用(Spring Boot 2.7.x默认集成Spring Security 5.7.x,正好满足版本要求)。将你的Spring Boot版本升级到2.7.x系列(比如2.7.15稳定版):

修改pom.xml中的parent节点:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.15</version>
</parent>

2. 移除手动指定的Spring Security子依赖

spring-boot-starter-security已经包含了spring-security-config和spring-security-web,手动指定这两个依赖的5.6.9版本会破坏版本一致性,直接删除以下内容:

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-config</artifactId>
    <version>5.6.9</version>
</dependency>
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-web</artifactId>
    <version>5.6.9</version>
</dependency>

3. 重新构建项目

  • 在IntelliJ中点击右侧Maven面板的「Reload All Maven Projects」刷新依赖
  • 执行命令行:mvn clean install 重新构建

额外提示

  • 尽量通过Spring Boot Parent来管理所有Spring生态的依赖版本,避免手动指定子模块版本,防止版本冲突
  • 若无法升级Spring Boot,需注意:Spring Authorization Server 0.4.0不兼容Spring Security 5.6.x,这种情况下只能降级Spring Authorization Server到兼容5.6.x的版本(比如0.3.1),但不推荐,因为旧版本可能存在已知漏洞

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 12:45:09