SpringBoot3集成Swagger出现错误Error starting ApplicationContext. To display the condition evaluation repor

简介: SpringBoot3集成SpringFox时出现错误。

1、问题

SpringBoot3集成SpringFox时出现错误

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
[main] o.s.boot.SpringApplication : Application run failed
java.lang.TypeNotPresentException: Type javax.servlet.http.HttpServletRequest not present

2、原因

截至目前,SpringFox已多年未更新,暂不支持SpingBoot3,导致SpingBoot3项目无法正常使用SpringFox去生成API文档,SpingBoot3项目建议使用SpringDoc
SpringFox仓库
SpringDoc官网

3、解决

无需降低SpringBoot版本,可以直接使用SpringDoc(SpringBoot3需使用SpringDoc2.0以上的版本)

3.1 引入SpringDoc

    <dependency>
      <groupId>org.springdoc</groupId>
      <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
      <version>2.4.0</version>
   </dependency>

3.2 Swagger配置

/**
 * Swagger配置
 */
@Configuration
public class SwaggerConfig {
   
    @Bean
    public OpenAPI springShopOpenAPI() {
   
        return new OpenAPI()
                .info(new Info().title("SpringBoot3 API")
                        .description("SpringBoot3 sample application")
                        .version("v1.0.0")
                        .license(new License().name("Apache 2.0").url("http://springdoc.org")))
                        .externalDocs(new ExternalDocumentation()
                        .description("SpringShop Wiki Documentation")
                        .url("https://springshop.wiki.github.org/docs"));

    }
}

3.3 打开文档

http://127.0.0.1:8080/swagger-ui/index.html

目录
相关文章
|
安全 Java Apache
微服务——SpringBoot使用归纳——Spring Boot中集成 Shiro——Shiro 身份和权限认证
本文介绍了 Apache Shiro 的身份认证与权限认证机制。在身份认证部分,分析了 Shiro 的认证流程,包括应用程序调用 `Subject.login(token)` 方法、SecurityManager 接管认证以及通过 Realm 进行具体的安全验证。权限认证部分阐述了权限(permission)、角色(role)和用户(user)三者的关系,其中用户可拥有多个角色,角色则对应不同的权限组合,例如普通用户仅能查看或添加信息,而管理员可执行所有操作。
666 0
|
安全 Java 数据安全/隐私保护
微服务——SpringBoot使用归纳——Spring Boot中集成 Shiro——Shiro 三大核心组件
本课程介绍如何在Spring Boot中集成Shiro框架,主要讲解Shiro的认证与授权功能。Shiro是一个简单易用的Java安全框架,用于认证、授权、加密和会话管理等。其核心组件包括Subject(认证主体)、SecurityManager(安全管理员)和Realm(域)。Subject负责身份认证,包含Principals(身份)和Credentials(凭证);SecurityManager是架构核心,协调内部组件运作;Realm则是连接Shiro与应用数据的桥梁,用于访问用户账户及权限信息。通过学习,您将掌握Shiro的基本原理及其在项目中的应用。
496 0
|
前端开发
SpringBoot2.3.1集成Knife4j接口文档
SpringBoot2.3.1集成Knife4j接口文档
1193 44
|
11月前
|
JSON 分布式计算 大数据
springboot项目集成大数据第三方dolphinscheduler调度器
springboot项目集成大数据第三方dolphinscheduler调度器
718 3
|
11月前
|
缓存 JSON 前端开发
第07课:Spring Boot集成Thymeleaf模板引擎
第07课:Spring Boot集成Thymeleaf模板引擎
918 0
第07课:Spring Boot集成Thymeleaf模板引擎
|
11月前
|
Java 关系型数据库 MySQL
springboot项目集成dolphinscheduler调度器 实现datax数据同步任务
springboot项目集成dolphinscheduler调度器 实现datax数据同步任务
1022 2
|
11月前
|
分布式计算 Java 大数据
springboot项目集成dolphinscheduler调度器 可拖拽spark任务管理
springboot项目集成dolphinscheduler调度器 可拖拽spark任务管理
547 2
|
缓存 安全 Java
Shiro简介及SpringBoot集成Shiro(狂神说视频简易版)
Shiro简介及SpringBoot集成Shiro(狂神说视频简易版)
926 7
|
缓存 Java 数据库
SpringBoot集成Ehcache缓存使用指南
以上是SpringBoot集成Ehcache缓存的基本操作指南,帮助你在实际项目中轻松实现缓存功能。当然,Ehcache还有诸多高级特性,通过学习和实践,你可以更好地发挥它的威力。
962 20