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

使用spring-boot-starter-oauth2-resource-server时JwtDecoder未自动注入问题

问题根本原因

你项目的Spring Boot插件版本与依赖包版本跨版本混用导致自动配置逻辑异常:

  • gradle plugins块中声明的org.springframework.boot插件版本为2.2.5.RELEASE
  • dependencies块中所有Spring Boot starter依赖的版本手动指定为2.3.4.RELEASE
    2.3.x版本对OAuth2资源服务器的JwtDecoder自动配置类OAuth2ResourceServerJwtConfiguration做过逻辑调整,与2.2.x版本的插件加载逻辑不兼容,因此即使你配置了正确的issuer-uri,也不会触发自动创建JwtDecoder Bean的逻辑。

解决方法

无需自定义JwtDecoder Bean,只要统一Spring Boot版本即可,二选一即可:

方案1:升级插件版本与依赖对齐

修改plugins块中的Spring Boot插件版本为2.3.4.RELEASE:

plugins {
    id 'java'
    id "io.spring.dependency-management" version "1.0.9.RELEASE"
    id "org.springframework.boot" version "2.3.4.RELEASE" // 仅修改该行
    id "org.owasp.dependencycheck" version "6.0.2"
}

建议同时删除所有dependencies中spring-boot-starter开头依赖的手动version声明,Spring Boot插件会自动管理统一版本,避免后续再出现版本冲突:

// 调整后示例,所有starter移除version字段
implementation group: 'org.springframework.boot', name: 'spring-boot-starter'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-log4j2'
// 其余spring-boot-starter系列依赖同理处理

方案2:降级依赖版本与插件对齐

将所有spring-boot-starter开头的依赖版本统一修改为2.2.5.RELEASE即可。

生效校验

修改完成后清理构建缓存重启项目,删除之前自定义的jwtDecoderByIssuerUri方法,确认application.yml中的issuer-uri占位符可以正常解析,即可正常触发自动配置逻辑,不会再报找不到JwtDecoder的错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.06 08:24:03