- 异常信息
Failed to start bean ‘documentationPluginsBootstrapper’; nested exception is java.lang.NullPointerException

原因分析
我这里使用的springboot版本是2.6.7 ,knife4j版本是3.0.3, 由于Springfox使用的路径匹配是基于AntPathMatcher,而Spring Boot 2.6.X使用的是PathPatternMatcher,所以将MVC的路径匹配规则改成 AntPathMatcher解决方案
spring:
mvc:
pathmatch:
#Springfox使用的路径匹配是基于AntPathMatcher的,而Spring Boot 2.6.X使用的是PathPatternMatcher 解决knife4j匹配boot2.6.7 boot版本过高的问题
matching-strategy: ant_path_matcher
配置类中knife4j版本是3.0.X使用@EnableSwagger2,其他低版本使用@EnableSwagger2WebMvc
@Configuration
@EnableKnife4j
@EnableSwagger2
public class Knife4jConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.OAS_30)
.host("127.0.0.1:8001")
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.ddz.rabbitmq"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("RabbitMq")
.description("RabbitMq 工作模式,延迟队列测试接口")
.termsOfServiceUrl("http:/127.0.0.1:8001/")
.version("1.0")
.build();
}
}
- 这样配置后使用boot2.6.7版本启动后就不会报错了

版权声明:本文为weixin_45626288原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。