此问题在此处已有答案:
Spring Boot 2.6.0 / Spring fox 3 - Failed to start bean 'documentationPluginsBootstrapper'(12个答案)
8个月前关门了。
Springfox 3.0.0不能与Sping Boot 2.6.0一起工作,升级后我得到以下错误
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 "this.condition" is null
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.enkindle.AntivirusApplication.main(AntivirusApplication.java:16)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.NullPointerException: Cannot invoke "org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getPatterns()" because "this.condition" is null
at springfox.documentation.spring.web.WebMvcPatternsRequestConditionWrapper.getPatterns(WebMvcPatternsRequestConditionWrapper.java:56)
at springfox.documentation.RequestHandler.sortedPaths(RequestHandler.java:113)
at springfox.documentation.spi.service.contexts.Orderings.lambda$byPatternsCondition$3(Orderings.java:89)
at java.base/java.util.Comparator.lambda$comparing$77a9974f$1(Comparator.java:473)
at java.base/java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
at java.base/java.util.TimSort.sort(TimSort.java:234)
at java.base/java.util.Arrays.sort(Arrays.java:1307)
at java.base/java.util.ArrayList.sort(ArrayList.java:1721)
at java.base/java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:392)
at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258)
at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258)
at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258)
at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
at springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider.requestHandlers(WebMvcRequestHandlerProvider.java:81)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
at springfox.documentation.spring.web.plugins.AbstractDocumentationPluginsBootstrapper.withDefaults(AbstractDocumentationPluginsBootstrapper.java:107)
at springfox.documentation.spring.web.plugins.AbstractDocumentationPluginsBootstrapper.buildContext(AbstractDocumentationPluginsBootstrapper.java:91)
at springfox.documentation.spring.web.plugins.AbstractDocumentationPluginsBootstrapper.bootstrapDocumentationPlugins(AbstractDocumentationPluginsBootstrapper.java:82)
at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.start(DocumentationPluginsBootstrapper.java:100)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)
... 19 common frames omitted
8条答案
按热度按时间s6fujrry1#
只有在主类中添加
@EnableWebMvc
才解决了问题:js81xvg62#
我知道这不能直接解决你的问题,但是考虑一下迁移到springdoc,most recent release支持Sping Boot 2.6.0。Springfox在这一点上是如此的bug,使用起来是一个痛苦。我在两年前迁移到
springdoc
,因为它支持Spring WebFlux,我对此非常高兴。另外,它还支持Kotlin协同程序,我不确定Springfox是否支持。如果您决定进行迁移,
springdoc
甚至还提供了迁移指南。4uqofj5v3#
到目前为止,Springfox 3.0.0只能与Spring 2.6.0-M2一起使用,而不能与以上版本一起使用。请参阅开放的Springfox问题https://github.com/springfox/springfox/issues/3462。在那里你还可以找到一些在问题解决之前可以使用的解决方法。
例如,将此
Bean
添加到您的Swagger配置:**EDIT:**服务器启动,但未返回API信息:
规范中未定义操作!
真是一团糟。
EDIT 2:@Héctor提到
spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER
也要加到application.properties
上,操作会重新显示出来,但是我不知道在任何情况下是否可以设置这个属性,因为它可能会干扰其他的约束。deyfvvtc4#
对于springfox 3.0.0和springboot 2.6.1,请使用此配置并添加此标记@Configuration @EnableWebMvc
9cbw7uwe5#
一种可能的解决方案是:
**1-**在
application.properties
中设置spring.mvc.pathmatch.matching-strategy: ant_path_matcher
**2-**将以下Bean添加到SwaggerConfig类中:
hhhhsw的制作人员
mw3dktmi6#
我在上一个项目中遇到了同样的问题,似乎Springfox依赖项在spring2.6.x中遇到了问题。我发现了问题是什么,它是关于Springfox依赖项的,所有spring开发人员在spring2.6.x之后都遇到了同样的问题
所以他们都给予了移植到springdoc的建议。你可以在这里找到所有的东西:
https://springdoc.org/#migrating-from-springfox
mgdq6dx17#
迁移步骤:
1.仅维护上述依赖关系。
1.删除早期版本的库包含。特别是删除springfox-swagger 2和springfox-swagger-ui包含。
1.移除@EnableSwagger2注解
1.添加springfox-boot-starter启动程序
1.如果您正在使用WebMvc,并且它是一个非springboot项目,但您还没有使用@EnableWebMvc注解,请添加此注解。
来源:doc_link
ct2axkht8#
我把依存:
并删除:
在这里解决!