当前位置: 首页> 汽车> 时评 > 天元建设集团有限公司第二公司_1688黄页网免费网站_网站设计公司有哪些_sem和seo是什么

天元建设集团有限公司第二公司_1688黄页网免费网站_网站设计公司有哪些_sem和seo是什么

时间:2025/7/11 0:39:31来源:https://blog.csdn.net/syg1207/article/details/145678303 浏览次数: 0次
天元建设集团有限公司第二公司_1688黄页网免费网站_网站设计公司有哪些_sem和seo是什么

1. 添加依赖

<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.6.5</version>
</parent>
<dependency><groupId>io.springfox</groupId><artifactId>springfox-boot-starter</artifactId><version>3.0.0</version>
</dependency>

2.  添加配置文件

application.yml 或applicaiton.properties 中添 必须 加如下配置

spring:mvc:pathmatch:matching-strategy: ant_path_matcher

3.  启动类上添加@EnableSwagger2 注解

4. 访问地址

http://127.0.0.1:8080/swagger-ui/index.html

 springboot其他版本可参考:Springboot ✚ Swagger各版本整理_swagger版本-CSDN博客

5. 遇到的问题

5.1 报错信息

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

5.2 问题原因

Springfox 设置 Spring MVC 的路径匹配策略是 ant-path-matcher,而 Spring Boot 2.6.x版本的默认匹配策略是 path-pattern-matcher,这就造成了上面的报错

5.3 解决方法 
  • 尝试使用 spring.mvc.pathmatch.matching-strategy: ant_path_matcher,未生效。这是网上大多数的解决办法

 实际解决方法:

@Configuration
public class WebConfiguration {@Beanpublic static BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() {return new BeanPostProcessor() {@Overridepublic Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) {customizeSpringfoxHandlerMappings(getHandlerMappings(bean));}return bean;}private <T extends RequestMappingInfoHandlerMapping> void customizeSpringfoxHandlerMappings(List<T> mappings) {List<T> copy = mappings.stream().filter(mapping -> mapping.getPatternParser() == null).collect(Collectors.toList());mappings.clear();mappings.addAll(copy);}@SuppressWarnings("unchecked")private List<RequestMappingInfoHandlerMapping> getHandlerMappings(Object bean) {try {Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings");field.setAccessible(true);return (List<RequestMappingInfoHandlerMapping>) field.get(bean);} catch (IllegalArgumentException | IllegalAccessException e) {throw new IllegalStateException(e);}}};}
}

参考文档: SpringBoot2.6.x 整合swagger3.0 报错Failed to start bean ‘documentationPluginsBootstrapper‘_spring.mvc.pathmatch.matching-strategy 不生效-CSDN博客

关键字:天元建设集团有限公司第二公司_1688黄页网免费网站_网站设计公司有哪些_sem和seo是什么

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: