Error creating bean with name ‘apiModelSpecificationReader‘ defined in URL

问题:

启动项目的时候,报错了

复制代码
org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'apiModelSpecificationReader' defined in URL 
[jar:file:/D:/.gradle/caches/modules-2/files-2.1/io.springfox/springfox-spring-web/3.0.0/a76f2fbe805bfd2798e20dc8f2cfbfad554d52da/springfox-spring-web-3.0.0.jar!/springfox/documentation/spring/web/scanners/ApiModelSpecificationReader.class]: 
Unsatisfied dependency expressed through constructor parameter 0; nested exception is 
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 
'springfox.documentation.schema.ModelSpecificationProvider' available: expected at least 1 
bean which qualifies as autowire candidate. Dependency annotations: 
{@org.springframework.beans.factory.annotation.Qualifier(value=cachedModels)}

检查了下swagger的版本,用的是:

复制代码
    implementation("io.swagger:swagger-annotations:1.5.20")
    implementation("io.springfox:springfox-swagger2:2.9.2")
    implementation("io.springfox:springfox-swagger-ui:2.9.2")
    implementation("io.springfox:springfox-swagger-common:2.9.2")

提示却是3.0.0

复制代码
[jar:file:/D:/.gradle/caches/modules-2/files-2.1/
io.springfox/springfox-spring-web/3.0.0

复制了下路径,检查了下,确实是如此。

原来是新的项目swagger用的是3.0.0,用的是一样的路径,导致影响。

处理1:

把springfox-spring-web目录下的3.0.0目录删了,再启动,是正常的。

但这样的话,有弄先的项目,又会出问题。

处理2:

在build.grale文件里面添加: exclude group: 'io.springfox', module: 'springfox-boot-starter'

复制代码
configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
    all {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
        exclude group: 'ch.qos.logback'
        exclude group: 'org.apache.solr'
        exclude group: 'io.springfox', module: 'springfox-boot-starter'
    }
}

这样启动就不受影响了。

总结:

启动报Error creating bean with name 'apiModelSpecificationReader' defined in URL 是版本不一致的问题,加个去除对应模块去处理:exclude group: 'io.springfox', module: 'springfox-boot-starter'

相关推荐
召田最帅boy4 天前
Swagger使用教程
swagger
闲人编程9 天前
OpenAPI/Swagger规范与API文档自动化
运维·自动化·json·swagger·schema·openapi·codecapsule
一念一花一世界9 天前
接口管理工具选型:Swagger与PostIn全面对比指南
测试工具·postman·swagger·postin·接口管理工具
一念一花一世界10 天前
接口管理工具选型:Postman、Swagger与PostIn的全面对比指南
测试工具·postman·swagger·接口管理工具
西部森林牧歌24 天前
Postman、swagger、PostIn接口管理工具详细纵评
postman·swagger·postin·接口管理工具
西部森林牧歌25 天前
接口管理工具选型指南:swagger与PostIn深度对比
swagger·postin·tiklab devops·接口管理工具
wangmengxxw1 个月前
Swagger技术
java·swagger
猿与禅1 个月前
SpringBoot 2.x 升级到 3.x 时 Swagger 迁移完整指南
swagger·springboot升级·springboot3.0·swagger3.0
東雪木1 个月前
Spring Boot 2.x 集成 Knife4j (OpenAPI 3) 完整操作指南
java·spring boot·后端·swagger·knife4j·java异常处理
一念一花一世界1 个月前
swagger和PostIn,开源免费接口管理工具选型指南
api·swagger·postin·接口管理工具