SpringBoot升级后,这服务一个星期都没跑起来,这是怎么回事呢?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1189个文字,预计阅读时间需要5分钟。
上一阶段的升级过程中差异不大,已跑起来90%。本周解决了一点点小问题,服务已恢复正常。接着测试了一些其他服务,又发现了新的问题,持续中。
上一次的升级过程中差不多已经跑起来90%了,这周一上班解决完一点小问题,服务已经正常跑起来了,于是再拿着一些其他的服务测试了一下,又发现了一些其他的报错,所以继续。
14. DiscoveryEnabledServer Not Found
主要问题还是 eureka 中没有了 ribbon 相关的依赖。
Caused by: java.lang.NoClassDefFoundError: com/netflix/niws/loadbalancer/DiscoveryEnabledServer
at java.lang.Class.getDeclaredMethods0(Native Method) ~[?:?]
at java.lang.Class.privateGetDeclaredMethods(Class.java:3167) ~[?:?]
at java.lang.Class.getDeclaredMethods(Class.java:2310) ~[?:?]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:467) ~[spring-core-5.3.23.jar:5.3.23]
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.3.23.jar:5.3.23]
解决方案:手动引入相关依赖包。
<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-loadbalancer</artifactId>
<version>2.7.18</version>
</dependency>
<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-eureka</artifactId>
<version>2.7.18</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
<version>2.2.10.RELEASE</version>
</dependency>
15. 中间件循环依赖
依然是循环依赖报错,之前没注意看代码,简单的设置了一下为延迟初始化,仔细一看发现代码这样写的,你细品。
然后启动报错:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cachesEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/cache/CachesEndpointAutoConfiguration.class]: Unsatisfied dependency expressed through method 'cachesEndpoint' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Requested bean is currently in creation: Is there an unresolvable circular reference?
16. CacheMetricsRegistrarConfiguration 报错
由于在解决 15 的问题一开始是设置为延迟初始化,然后启动发现仍然报错。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.metrics.cache.CacheMetricsRegistrarConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.autoconfigure.metrics.cache.CacheMetricsRegistrarConfiguration]: Constructor threw exception; nested exception is java.lang.StackOverflowError
解决方案:去掉 Autowired 注入,15和16的问题全部解决。
17. kafka-clients 版本和 spring-kafka 不兼容
升级后默认spring-kafka是2.8.10版本,KafkaTemplate 报错找不到类,原因在于本地kafka-clients使用的是 2.3.0 版本。
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.kafka.core.KafkaTemplate] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@9e89d68]
Caused by: java.lang.NoClassDefFoundError: org/apache/kafka/clients/consumer/ConsumerGroupMetadata
解决方案:kafka-clients升级到兼容版本 3.0.2 ,这个版本是 spring-cloud-dependency 中依赖的版本。
18. swagger启动报错
这个报错是因为新版本 Spring Boot 将 Spring MVC 默认路径匹配策略由AntPathMatcher改成了PathPatternParser,这个报错在我这里是WARN,而且非常隐蔽,需要仔细查找。
[WARN] [2022.11.08 16:17:39.963] [10.135.0.95] [] [main] [org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext()] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
解决方案:配置成原来的AntPathMatcher,添加配置spring.mvc.pathmatch.matching-strategy= ANT_PATH_MATCHER
这个报错信息是一行 WARN 日志,非常难找,另外原因是根据网上信息搜索定位到的,这个报错信息我真的服了。
19. spring-session依赖报错
启动报错信息:
n attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.autoconfigure.session.SessionAutoConfiguration$ServletSessionConfiguration.cookieSerializer(SessionAutoConfiguration.java:109)
The following method did not exist:
'void org.springframework.session.web.www.558idc.com/usa.html转载请说明出处】
本文共计1189个文字,预计阅读时间需要5分钟。
上一阶段的升级过程中差异不大,已跑起来90%。本周解决了一点点小问题,服务已恢复正常。接着测试了一些其他服务,又发现了新的问题,持续中。
上一次的升级过程中差不多已经跑起来90%了,这周一上班解决完一点小问题,服务已经正常跑起来了,于是再拿着一些其他的服务测试了一下,又发现了一些其他的报错,所以继续。
14. DiscoveryEnabledServer Not Found
主要问题还是 eureka 中没有了 ribbon 相关的依赖。
Caused by: java.lang.NoClassDefFoundError: com/netflix/niws/loadbalancer/DiscoveryEnabledServer
at java.lang.Class.getDeclaredMethods0(Native Method) ~[?:?]
at java.lang.Class.privateGetDeclaredMethods(Class.java:3167) ~[?:?]
at java.lang.Class.getDeclaredMethods(Class.java:2310) ~[?:?]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:467) ~[spring-core-5.3.23.jar:5.3.23]
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.3.23.jar:5.3.23]
解决方案:手动引入相关依赖包。
<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-loadbalancer</artifactId>
<version>2.7.18</version>
</dependency>
<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-eureka</artifactId>
<version>2.7.18</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
<version>2.2.10.RELEASE</version>
</dependency>
15. 中间件循环依赖
依然是循环依赖报错,之前没注意看代码,简单的设置了一下为延迟初始化,仔细一看发现代码这样写的,你细品。
然后启动报错:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cachesEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/cache/CachesEndpointAutoConfiguration.class]: Unsatisfied dependency expressed through method 'cachesEndpoint' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Requested bean is currently in creation: Is there an unresolvable circular reference?
16. CacheMetricsRegistrarConfiguration 报错
由于在解决 15 的问题一开始是设置为延迟初始化,然后启动发现仍然报错。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.metrics.cache.CacheMetricsRegistrarConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.autoconfigure.metrics.cache.CacheMetricsRegistrarConfiguration]: Constructor threw exception; nested exception is java.lang.StackOverflowError
解决方案:去掉 Autowired 注入,15和16的问题全部解决。
17. kafka-clients 版本和 spring-kafka 不兼容
升级后默认spring-kafka是2.8.10版本,KafkaTemplate 报错找不到类,原因在于本地kafka-clients使用的是 2.3.0 版本。
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.kafka.core.KafkaTemplate] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@9e89d68]
Caused by: java.lang.NoClassDefFoundError: org/apache/kafka/clients/consumer/ConsumerGroupMetadata
解决方案:kafka-clients升级到兼容版本 3.0.2 ,这个版本是 spring-cloud-dependency 中依赖的版本。
18. swagger启动报错
这个报错是因为新版本 Spring Boot 将 Spring MVC 默认路径匹配策略由AntPathMatcher改成了PathPatternParser,这个报错在我这里是WARN,而且非常隐蔽,需要仔细查找。
[WARN] [2022.11.08 16:17:39.963] [10.135.0.95] [] [main] [org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext()] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
解决方案:配置成原来的AntPathMatcher,添加配置spring.mvc.pathmatch.matching-strategy= ANT_PATH_MATCHER
这个报错信息是一行 WARN 日志,非常难找,另外原因是根据网上信息搜索定位到的,这个报错信息我真的服了。
19. spring-session依赖报错
启动报错信息:
n attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.autoconfigure.session.SessionAutoConfiguration$ServletSessionConfiguration.cookieSerializer(SessionAutoConfiguration.java:109)
The following method did not exist:
'void org.springframework.session.web.www.558idc.com/usa.html转载请说明出处】

