After using Swagger in the latest SpringBoot 2.6 and introducing springfox-swagger2 (version 2.9.2), the project starts reporting that the documentationPluginsBootstrapper cannot be loaded:
ERROR [main][org.springframework.boot.SpringApplication]:819 - Application run failed org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54) at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) at java.base/java.lang.Iterable.forEach(Iterable.java:75) at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155) at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) at com.ikang.mis.sms.MisSmsApplication.main(MisSmsApplication.java:10) Caused by: java.lang.NullPointerException: null at springfox.documentation.spi.service.contexts.Orderings$8.compare(Orderings.java:112) at springfox.documentation.spi.service.contexts.Orderings$8.compare(Orderings.java:109) at com.google.common.collect.ComparatorOrdering.compare(ComparatorOrdering.java:37) at java.base/java.util.TimSort.countRunAndMakeAscending(TimSort.java:355) at java.base/java.util.TimSort.sort(TimSort.java:220) at java.base/java.util.Arrays.sort(Arrays.java:1442) at com.google.common.collect.Ordering.sortedCopy(Ordering.java:855) at springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider.requestHandlers(WebMvcRequestHandlerProvider.java:57) at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper$2.apply(DocumentationPluginsBootstrapper.java:138) at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper$2.apply(DocumentationPluginsBootstrapper.java:135) at com.google.common.collect.Iterators$7.transform(Iterators.java:750) at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:47) at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:47) at com.google.common.collect.MultitransformedIterator.hasNext(MultitransformedIterator.java:52) at com.google.common.collect.MultitransformedIterator.hasNext(MultitransformedIterator.java:50) at com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:249) at com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:209) at com.google.common.collect.FluentIterable.toList(FluentIterable.java:614) at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.defaultContextBuilder(DocumentationPluginsBootstrapper.java:111) at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.buildContext(DocumentationPluginsBootstrapper.java:96) at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.start(DocumentationPluginsBootstrapper.java:167) at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ... 14 common frames omitted Process finished with exit code 1
The above error is caused by a bug in Springfox, which is assuming how SpringMVC is built, but this does not always hold true. Specifically, it assumes that MVC’s path matching will use an Ant-based path matcher, rather than a PathPattern-based matcher. PathPattern-based matching is already an option, and is the default option in SpringBoot 2.6.
As described in the Spring Boot 2.6 release notes, you can restore the configuration that Springfox assumes will be used by setting Spring.mvc.pathmatch.matching-strategy to ant path matcher in the application.properties file. Note that this feature only works when Spring Boot’s executor is not used. The executor always uses path pattern-based parsing, regardless of the configured match strategy. If you want to use it with Spring Boot 2.6 and later with the executor, you will need to make changes to Springfox.