一、控制台的报错信息
2021-12-29 15:15:04 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException

二、解决办法有两种任选其一
1.方法一:配置 WebMvcConfigurer.java
package com.clesun.brandarchive.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
/**
* 解决高版本springboot整合swagger启动报错Failed to start bean 'documentationPluginsBootstrapper' 问题
* @author Administrator
*/
@Configuration
public class WebMvcConfigurer extends WebMvcConfigurationSupport {
/**
* 发现如果继承了WebMvcConfigurationSupport,则在yml中配置的相关内容会失效。 需要重新指定静态资源
* @param registry
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations(
"classpath:/static/");
registry.addResourceHandler("swagger-ui.html", "doc.html").addResourceLocations(
"classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations(
"classpath:/META-INF/resources/webjars/");
super.addResourceHandlers(registry);
}
}
2.方法二:yml文件里进行配置
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
3.启动
然后在页面就可以看到swagger

本文档介绍了在Spring Boot应用中遇到Swagger启动失败的问题,错误信息为`Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException`。提供两种解决方案:1) 创建并配置`WebMvcConfigurer`类,覆盖默认资源配置;2) 在YML文件中配置`spring.mvc.pathmatch.matching-strategy: ant_path_matcher`。应用上述方法后,Swagger将正常启动并可供访问。
381

被折叠的 条评论
为什么被折叠?



