一、控制台的报错信息
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*/@Overridepublic 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