概述
项目场景:
在已开发的项目中,SpringBoot版本2.3.12升级到2.6.3后引发的一系列问题。
问题描述
问题1:
项目中引入的jar包,引用的类或方法不存在等
完整报错信息:
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.hibernate.validator.internal.xml.config.ValidationBootstrapParameters.<init>(ValidationBootstrapParameters.java:65)
The following method did not exist:
javax.validation.BootstrapConfiguration.getClockProviderClassName()Ljava/lang/String;
The calling method's class, org.hibernate.validator.internal.xml.config.ValidationBootstrapParameters, was loaded from the following location:
jar:file:/Users/albert/code/repo/org/hibernate/validator/hibernate-validator/6.2.0.Final/hibernate-validator-6.2.0.Final.jar!/org/hibernate/validator/internal/xml/config/ValidationBootstrapParameters.class
The called method's class, javax.validation.BootstrapConfiguration, is available from the following locations:
jar:file:/Users/albert/code/repo/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar!/javax/validation/BootstrapConfiguration.class
jar:file:/Users/albert/code/repo/jakarta/validation/jakarta.validation-api/2.0.2/jakarta.validation-api-2.0.2.jar!/javax/validation/BootstrapConfiguration.class
jar:file:/Users/albert/code/repo/javax/javaee-api/8.0/javaee-api-8.0.jar!/javax/validation/BootstrapConfiguration.class
The called method's class hierarchy was loaded from the following locations:
javax.validation.BootstrapConfiguration: file:/Users/albert/code/repo/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar
Action:
Correct the classpath of your application so that it contains compatible versions of the classes org.hibernate.validator.internal.xml.config.ValidationBootstrapParameters and javax.validation.BootstrapConfiguration
Process finished with exit code 1
主要看最后提供的Action:
//纠正应用程序的类路径,使其包含类org的兼容版本。
Correct the classpath of your application so that it contains compatible versions of the classes org.
大部分出现该报错的主要原因有2个:
1、一般这种错误都是重复引入包了,看具体报错的是哪个类,把这个依赖注释掉
2、最大的问题是在于包版本的问题,版本没对上。让两者的版本都处于接近的版本更新迭代,
例如:SpringBoot版本2.6.3处于最新的前几代版本,相对于找不到方法或类的jar包也应该处于最新几代的版本。
问题2:
SpringBoot 2.6.x不推荐使用循环依赖,这是一个好消息,SpringBoot从底层逐渐引导开发者书写规范的代码,同时也是个忧伤的消息,循环依赖的应用场景实在是太广泛了。
如果从低版本升级到2.6.x,那么很大概率遇到的第一个问题便是循环依赖问题。
原文链接:https://blog.csdn.net/QIU176161650/article/details/122111567
完整报错信息:
Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.
解决方法:
1、最简单的方式是在全局配置文件中允许循环引用存在,此属性默认值为false,显示声明为true,可回避项目启动时控制台循环引用异常。
spring:
main:
allow-circular-references: true
2、使用方法的返回值获取实例对象,替换通过成员变量注入实例对象。
详情参考原作者:https://blog.csdn.net/m0_63836794/article/details/123082646
问题3:
SpringBoot项目中集成了knife4j,在将SpringBoot更新到2.6.0后启动项目报错 Failed to start bean ‘documentationPluginsBootstrapper’; nested exception is java.lang.NullPointerException,导致系统不能正常启动。
原文链接:https://blog.csdn.net/QIU176161650/article/details/122111567
完整报错信息:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-12-23 16:52:35.735 ERROR 15348 --- [
main] o.s.boot.SpringApplication
: 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 org.springframework.context.support.DefaultLifecycleProcessor$$Lambda$778/18341126.accept(Unknown Source)
at 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.chqiuu.test.TestApplication.main(TestApplication.java:23)
Caused by: java.lang.NullPointerException: 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 springfox.documentation.spi.service.contexts.Orderings$$Lambda$796/7205235.apply(Unknown Source)
at java.util.Comparator.lambda$comparing$77a9974f$1(Comparator.java:469)
at java.util.Comparator$$Lambda$68/3330950.compare(Unknown Source)
at java.util.TimSort.countRunAndMakeAscending(TimSort.java:351)
at java.util.TimSort.sort(TimSort.java:230)
at java.util.Arrays.sort(Arrays.java:1512)
at java.util.ArrayList.sort(ArrayList.java:1454)
at java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:387)
at java.util.stream.Sink$ChainedReference.end(Sink.java:258)
at java.util.stream.Sink$ChainedReference.end(Sink.java:258)
at java.util.stream.Sink$ChainedReference.end(Sink.java:258)
at java.util.stream.Sink$ChainedReference.end(Sink.java:258)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider.requestHandlers(WebMvcRequestHandlerProvider.java:81)
at springfox.documentation.spring.web.plugins.AbstractDocumentationPluginsBootstrapper$$Lambda$790/3038834.apply(Unknown Source)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:512)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
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)
... 15 common frames omitted
解决方法:
1、最直接简单的方法就是将springboot版本降级,但这也只是暂时解决问题的办法,不是长久之计;
2、如果有对Spring Boot 2.6.0的文档进行研究,会发现2.6.0开始使用基于PathPatternParser的路径匹配,而Springfox版本一直没有更新还是使用的AntPathMatcher导致了这个问题,要处理问题也很简单,修改yaml文件,将SpringBoot路劲匹配模式修改为AntPathMatcher就可以了,配置如下:spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER
修改application.yml文件配置:
spring:
mvc:
pathmatch:
matching-strategy: ANT_PATH_MATCHER
最后
以上就是土豪萝莉为你收集整理的SpringBoot2.6.3版本的问题项目场景:问题描述的全部内容,希望文章能够帮你解决SpringBoot2.6.3版本的问题项目场景:问题描述所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复