启动SpringBoot报,报错信息:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException: Cannot invoke "org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getPatterns()" because the return value of "springfox.documentation.spring.web.WebMvcPatternsRequestConditionWrapper._jr$ig$condition(Object)" is null
2022-08-25 17:44:39.844 WARN 16760 --- [ main] o.a.c.loader.WebappClassLoaderBase : The web application [ROOT] appears to have started a thread named [oracle.jdbc.driver.BlockSource.ThreadedCachingBlockSource.BlockReleaser] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.base@17.0.4.1/jdk.internal.misc.Unsafe.park(Native Method)
java.base@17.0.4.1/java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:252)
java.base@17.0.4.1/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:1672)
app//oracle.jdbc.internal.Monitor$WaitableMonitor.monitorWait(Monitor.java:258)
app//oracle.jdbc.internal.Monitor$WaitableMonitor.monitorWait(Monitor.java:240)
app//oracle.jdbc.driver.BlockSource$ThreadedCachingBlockSource$BlockReleaser.run(BlockSource.java:345)
核查
项目使用了Springboot2.7、knife4j3(springfox3.0.0)、Redission27版,经过苦苦排查,是由于Springboot 2.6+ 与springfox3.0.0 不兼容导致,最终还是经过大佬找资料+指导,添加以下配置解决:
1.SpringBoot配置文件添加配置:
spring:
mvc:
pathmatch:
# https://doc.xiaominfo.com/docs/quick-start
matching-strategy: ant_path_matcher
2.添加配置启动代码,可以在swagge或者knife4j配置类加上:
添加1配置后,knife4j能起来了,但是用了Redission27一样启动报**Failed to start bean ‘documentationPluginsBootstrapper’**异常,需要继续添加配置处理
@Bean
public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(
WebEndpointsSupplier webEndpointsSupplier,
ServletEndpointsSupplier servletEndpointsSupplier,
ControllerEndpointsSupplier controllerEndpointsSupplier,
EndpointMediaTypes endpointMediaTypes,
CorsEndpointProperties corsProperties,
WebEndpointProperties webEndpointProperties,
Environment environment) {
List<ExposableEndpoint<?>> allEndpoints = new ArrayList<ExposableEndpoint<?>>();
Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
allEndpoints.addAll(webEndpoints);
allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
String basePath = webEndpointProperties.getBasePath();
EndpointMapping endpointMapping = new EndpointMapping(basePath);
boolean shouldRegisterLinksMapping =
this.shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
return new WebMvcEndpointHandlerMapping(
endpointMapping,
webEndpoints,
endpointMediaTypes,
corsProperties.toCorsConfiguration(),
new EndpointLinksResolver(allEndpoints, basePath),
shouldRegisterLinksMapping,
null);
}
private boolean shouldRegisterLinksMapping(
WebEndpointProperties webEndpointProperties, Environment environment, String basePath) {
return webEndpointProperties.getDiscovery().isEnabled()
&& (StringUtils.hasText(basePath)
|| ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
}
吐槽springfox3的同时,完美启动项目。