iis服务器助手广告
返回顶部
首页 > 资讯 > 后端开发 > JAVA >解决“Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception is java.lang.NullPoint”
  • 647
分享到

解决“Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception is java.lang.NullPoint”

javaspringbootspring 2023-09-08 18:09:37 647人浏览 薄情痞子
摘要

当你的spring-boot版本是2.6.x并且你的swagger版本是3.0.0以上的时候,项目启动会报错“org.springframework.context.ApplicationContextException: Failed t

当你的spring-boot版本是2.6.x并且你的swagger版本是3.0.0以上的时候,项目启动会报错“org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException”

解决办法

步骤一、

添加配置

spring:  mvc:    pathmatch:      matching-strategy: ant_path_matcher

步骤二、

添加配置类

import org.springframework.beans.BeansException;import org.springframework.beans.factory.config.BeanPostProcessor;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.util.ReflectionUtils;import org.springframework.WEB.servlet.mvc.method.RequestMappingInfoHandlerMapping;import springfox.documentation.spring.web.plugins.WebFluxRequestHandlerProvider;import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider;import java.lang.reflect.Field;import java.util.List;import java.util.stream.Collectors;@Configurationpublic class BeanPostProcessorConfig {    @Bean    public static BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() {        return new BeanPostProcessor() {            @Override            public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {                if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) {                    customizeSpringfoxHandlerMappings(getHandlerMappings(bean));                }                return bean;            }            private  void customizeSpringfoxHandlerMappings(List mappings) {                List copy = mappings.stream()                        .filter(mapping -> mapping.getPatternParser() == null)                        .collect(Collectors.toList());                mappings.clear();                mappings.addAll(copy);            }            @SuppressWarnings("unchecked")            private List getHandlerMappings(Object bean) {                try {                    Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings");                    field.setAccessible(true);                    return (List) field.get(bean);                } catch (IllegalArgumentException | IllegalAccessException e) {                    throw new IllegalStateException(e);                }            }        };    }}

来源地址:https://blog.csdn.net/cxclll/article/details/126745903

--结束END--

本文标题: 解决“Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception is java.lang.NullPoint”

本文链接: https://www.lsjlt.com/news/400442.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作