错误
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)