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

OpenAPI v3相关:IntelliJ IDEA提示无法解析符号‘annotations’

问题原因与解决方法

核心问题

你导入的io.swagger.annotations.Api和Operation是Swagger 2.x版本的注解,但你使用的springdoc-openapi是适配OpenAPI 3规范的工具,两者的注解包完全不同,且springdoc-openapi-ui依赖中默认不包含Swagger 2的注解类,所以IDEA提示无法解析符号。

解决方法

方法一:改用OpenAPI 3标准注解(推荐)

直接替换为SpringDoc适配的OpenAPI 3注解,包路径为io.swagger.v3.oas.annotations:

// 替代原Api注解
import io.swagger.v3.oas.annotations.tags.Tag;
// Operation注解替换为OpenAPI 3版本
import io.swagger.v3.oas.annotations.Operation;

说明:Tag注解的作用和原Api一致,用于标记接口组;Operation注解的用法类似,但部分属性有调整,比如用summary替代原value字段,description字段保留。

方法二:保留Swagger 2注解,添加兼容依赖

如果需要继续使用原Swagger 2的注解,需要在build.gradle中额外引入Swagger 2注解的依赖包:

api "io.swagger.core.v3:swagger-annotations:2.2.15"

添加完成后,执行Gradle同步操作,IDEA即可识别到io.swagger.annotations包。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 12:10:50