解决引入Redisson 时 Knife4j-spring-boot 报错 Failed to start bean ‘documentationPluginsBootstrapper‘

在SpringBoot2.7.5版本中,由于Knife4j版本2.0.9和redisson-spring-boot-starter3.17.1的引入,导致actuator与swagger-ui出现冲突,表现为FailedtostartbeandocumentationPluginsBootstrapper错误。问题根源在于redisson-spring-boot-starter无意中引入了actuator。为解决这个问题,可以排除redisson对spring-boot-starter-actuator的依赖,通过在依赖管理中添加exclusions节点来实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SpringBoot 版本: 2.7.5

Knife4j 版本:2.0.9

redisson-spring-boot-starter 版本:3.17.1

在引入Redisson 后会报  Failed to start bean 'documentationPluginsBootstrapper' 的错误,

断点追踪发现是因为 /actuator 节点报错

这样原因就很明显了,是因为 actuator 与 swagger-ui 冲突

在引入redisson-spring-boot-starter 时会引入 actuator 导致报错

所以我们只需要在引入redisson时排除掉actuator 就可以正常访问了

<dependency>
    <groupId>org.redisson</groupId>
    <artifactId>redisson-spring-boot-starter</artifactId>
    <version>3.17.7</version>
    <exclusions>
        <exclusion>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <groupId>org.springframework.boot</groupId>
        </exclusion>
    </exclusions>
</dependency>
### 解决 `Failed to start bean documentationPluginsBootstrapper` 的 NullPointerException 问题 当遇到 `Failed to start bean documentationPluginsBootstrapper` 并伴随有 `NullPointerException` 错误,通常是因为 Spring Boot 应用程序在初始化 Knife4j 或者 Swagger 文档插件的过程中遇到了某些未预期的情况。具体原因可能涉及路径匹配策略不兼容等问题。 #### 修改路径匹配策略 为了使 Knife4jSpring Boot 更好地协同工作,可以调整应用程序中的路径匹配策略设置。通过指定 `spring.mvc.pathmatch.matching-strategy=ant_path_matcher` 可以解决一些由默认路径解析器引起的冲突[^5]: ```yaml spring: mvc: pathmatch: matching-strategy: ant_path_matcher ``` 此配置项的作用在于改变 URL 路径模式匹配的行为方式,使得其更符合传统风格的 Ant 风格通配符语法,从而减少潜在的错误发生几率。 #### 更新依赖版本 确保所使用的库是最新的稳定版也很重要。对于 Spring Boot 版本较高的项目来说,建议升级到与之相适应的新版本 Knife4j/Swagger UI 组件,因为旧版本可能存在已知缺陷或不再支持新特性[^4]。 #### 检查自定义配置类 如果存在自定义的Swagger配置类(如 `@Configuration` 注解标注),则需确认这些类内的逻辑不会导致 NPE 发生。例如,在创建 OpenAPI 对象实例之前应先验证必要的参数是否为空[^3]: ```kotlin @Configuration class SwaggerConfig { @Bean fun customOpenApi(): OpenAPI? { val info = Info() .title("My API Title") .version("1.0") // Ensure all required fields are set before returning the object. if (info.title != null && info.version != null) { return OpenAPI().info(info) } throw IllegalStateException("Invalid configuration detected.") } } ``` 上述代码片段展示了如何安全构建 OpenAPI 实例并处理可能出现的问题。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值