已解决 SpringBoot3 集成 Swagger 错误 creating bean with name ‘apiDocumentationScanner‘ defined in URL

错误

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
00:15:24.155 [main] ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'apiDocumentationScanner' defined in URL 

原因

 使用的springBoot版本太高3.x.x

解决方法(不需要降低SpringBoot版本) 

1.pop中删除原Swagger依赖,重新引入如下依赖(原因:springboot3需使用springdoc2.0以上的版本)

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
    <version>2.0.2</version>
</dependency>
<!-- 官方建议是springdoc替代springfox-->
<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
    <version>2.0.2</version>
</dependency>
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <optional>true</optional>
</dependency>

2.配置文件application.properties

# disposition SpringBoot Swagger
server.port=8080
# Configure the access path for the swagger document,Access address: http://127.0.0.1:8080/swagger-ui.html
springdoc.swagger-ui.path= /swagger-ui.html
# Logger Config
logging.level.com.hexadecimal=debug

3.swagger初始化配置(最基本的,如有需要可继续配置)

@Configuration//Tell the Spring container that this is a configuration class
public class SwaggerConfig {
//Visit the website:http://127.0.0.1:8080/swagger-ui/index.html
    @Bean
    public OpenAPI springShopOpenAPI() {
        return new OpenAPI()
                .info(new Info().title("SpringBoot Vue Test")
                        .description("SpringBoot+Vue Test Swagger debugging")
                        .version("v1")
                       
    }
   
}

4.运行 网址:http://127.0.0.1:8080/swagger-ui/index.html

 如还有问题,或不知如何写Controller,可参考Spring Boot 使用 Swagger3 生成 API 接口文档 - 知乎 (zhihu.com)

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值