Springboot中actuator与Swagger3版本冲突造成 Failed to start bean ‘documentationPluginsBootstrapper‘

springboot主程序启动时出现报错

org.springframework.context.ApplicationContextException:
 Failed to start bean 'documentationPluginsBootstrapper';
 nested exception is java.lang.NullPointerException

查询发现是使用国内Spring4All社区开发的依赖swagger-spring-boot-starter 与自身的Swagger 发送了冲突

解决方法:

在配置中添加一个新配置项

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    /**
     * 增加如下配置可解决Spring Boot 6.x 与Swagger 3.0.0 不兼容问题
     **/
    @Bean
    public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier, ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties corsProperties, WebEndpointProperties webEndpointProperties, Environment environment) {
        List<ExposableEndpoint<?>> allEndpoints = new ArrayList();
        Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
        allEndpoints.addAll(webEndpoints);
        allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
        allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
        String basePath = webEndpointProperties.getBasePath();
        EndpointMapping endpointMapping = new EndpointMapping(basePath);
        boolean shouldRegisterLinksMapping = this.shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
        return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes, corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath), shouldRegisterLinksMapping, null);
    }

    private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment, String basePath) {
        return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath) || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
    }
}

 启动成功

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
引用和都提到了报错信息"Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException"。这个错误是由于在启动时无法成功启动名为'documentationPluginsBootstrapper'的bean导致的。具体的报错原因是java.lang.NullPointerException,即空指针异常。这意味着在代码出现了一个空对象的引用,而没有对其进行处理,导致程序抛出了异常。 解决这个问题有一些方法可以尝试: 1. 方法一是将Spring Boot版本回退到2.5.X。这是因为可能在当前版本存在某些bug或问题,通过回退到旧版本可以解决这个问题。 2. 方法二是通过配置application.yml文件来解决。具体的配置路径可以参考上述引用的内容,根据报错信息提供的路径进行配置。 需要注意的是,具体哪种方法适用于你的情况还需要根据你的具体环境和代码结构来决定。建议你可以先尝试方法一,如果问题仍然存在,再尝试方法二。如果问题仍然无法解决,可能需要进一步检查代码逻辑和查看其他相关的错误信息来进行排查。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [解决报错Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception is java.lang....](https://blog.csdn.net/weixin_46411355/article/details/128884811)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [Swagger启动报错Failed to start bean ‘documentationPluginsBootstrapper](https://blog.csdn.net/threelifeadv/article/details/122449850)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值