springboot 错误

📕Application run failed

❌Failed to start bean ‘documentationPluginsBootstrapper’

spring boot 整合 swagger3 导致 Web 服务器无法启动的问题。

<!-- swagger3 API文档 -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-boot-starter</artifactId>
    <version>3.0.0</version>
</dependency>

当 spring boot 应用整合 swagger3 做接口文档开发时,无法直接启动原来的 spring 应用。

错误信息

2022-05-12 12:45:27.860 |- ERROR [restartedMain] org.springframework.boot.SpringApplication [830] -| Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
	...
Caused by: java.lang.NullPointerException: null
	at springfox.documentation.spring.web.WebMvcPatternsRequestConditionWrapper.getPatterns(WebMvcPatternsRequestConditionWrapper.java:56)
	... 

这个问题的主要原因是 SpringBoot 版本过高导致,如果你用的是 SpringBoot 2.5.x 及之前版本是没有这个问题的。

Spring Boot 2.6.X 使用 PathPattern 匹配路径,Swagger 引用的 Springfox 使用的路径匹配是基于 AntPathMatcher 的,所以要想解决这个问题需要添加配置,将springBoot MVC的路径匹配模式重新修改为 AntPathMatcher 即可。

spring: 
  mvc: 
    pathmatch:
      matching-strategy: ant_path_matcher

那有没有什么框架是采用 PathPattern 匹配路径的?

JApiDocs 一个两年没有更新的项目,但是生成接口文档确非常方便。

❌Unable to start web server

spring boot 整合 mybatis 导致 Web 服务器无法启动的问题。

<!-- mybatis 整合 -->
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>2.2.2</version>
</dependency>

当引用 mybatis-spring 依赖项后,是无法直接运行 spring 应用。

错误信息

2022-05-11 12:12:46.860 |- ERROR [restartedMain] org.springframework.boot.SpringApplication [830] -| Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
	...
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
	...

这是因为 mybatis-spring 里面的自动配置导致的,因此需要通过 @EnableAutoConfiguration 或 @SpringBootApplication 的 exclude 属性来排除 DataSourceAutoConfiguration.class 数据源配置类。

// spring boot 启动入口类里面配置
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})

这样又可以在不配置数据库的情况下正常启动 spring boot 应用了,也可以根据自己的配置文件来配置数据源。

【DataSourceAutoConfiguration 解析】



如果你是无意刷到这篇文章并看到这里,希望你给我的文章来一个赞赞👍👍。如果你不同意其中的内容或有什么问题都可以在下方评论区留下你的想法或疑惑,谢谢你的支持!!😀😀

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hjhcos

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值