转载

springboot 2.1.9 升级问题记录

将所有使用springboot1.5版本改为springboot2.1.9,springcloud版本为Greenwich.SR3,springboot与springcloud版本对应关系表: start.spring.io/actuator/in…

计划

由于1.5到2.0版本改动比较大,所以计划分步骤进行升级

  1. 先升级:gateway, eureka, config
  2. 后续再按各个业务需求,逐步升级业务系统

风险

  1. user,product,order,pay等其他系统是否可以正常使用,需要测试,并覆盖到所有的功能点
  2. gateway, eureka,config 本身功能是否有受到影响

步骤

升级 eureka,config比较顺利,改版本号后,就可以正常运行

gateway的过程比较曲折,以下为遇到的问题及解决方案

ZuulFallbackProvider找不到

启动提示 org.springframework.cloud.netflix.zuul.filters.route.ZuulFallbackProvider 找不到

springboot 2.1.9 升级问题记录

经过查询资料,原来新版本已经由ZuulFallbackProvider改为FallbackProvider,且代码由spring-cloud-netflix-core-1.3.4.RELEASE.jar移到spring-cloud-netflix-zuul-2.1.3.RELEASE.jar中

import org.springframework.cloud.netflix.zuul.filters.route.ZuulFallbackProvider;

改为

import org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider;

springboot 2.1.9 升级问题记录

EnableFeignClients找不到

启动提示 org.springframework.cloud.netflix.feign.EnableFeignClients 找不到

代码由spring-cloud-netflix-core-1.3.4.RELEASE.jar移到spring-cloud-openfeign-core-2.1.3.RELEASE.jar中

import org.springframework.cloud.netflix.feign.EnableFeignClients

改为

import org.springframework.cloud.openfeign.EnableFeignClients

Caused by: java.lang.ClassNotFoundException: org.springframework.boot.bind.RelaxedPropertyResolver

增加新包

<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
    <version>2.1.6</version>
</dependency>
复制代码

The bean 'tracingFilter', defined in class path resource [io/opentracing/contrib/spring/web/starter/ServerTracingAutoConfiguration.class], could not be registered

升级包 io.opentracing.contrib 相关的所有包,版本号 0.3.8

Caused by: java.lang.NoSuchMethodError: org.springframework.data.redis.cache.RedisCacheManager.(Lorg/springframework/data/redis/core/RedisOperations;)V

原因:com.xxx.core.util.support.conf.redis.RedisConf使用了RedisCacheManager(RedisOperations redisOperations)构造方法,但是在spring-data-redis 2.1.11中已经移除该构造方法,并改为build的方式

所以需要更改core-util库的RedisConf.java文件,但是由于core-util是公共的库,更改以后,会导致低版本引入该库出现问题,只能取消引用该库,再重新写一份RedisConf.java

public CacheManager cacheManager(RedisTemplate<?, ?> redisTemplate) {
   CacheManager cacheManager = new RedisCacheManager(redisTemplate);
   return cacheManager;
}

//改为
public CacheManager cacheManager(RedisConnectionFactory connectionFactory) {
    RedisCacheManager.RedisCacheManagerBuilder builder = RedisCacheManager
            .RedisCacheManagerBuilder
            .fromConnectionFactory(connectionFactory);
    return builder.build();
}
复制代码

Field redisTemplate in com.igetcool.gateway.template.impl.RedisTempImpl required a bean of type 'org.springframework.data.redis.core.RedisTemplate' that could not be found.

增加新包

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-redis</artifactId>
    <version>2.1.9.RELEASE</version>
</dependency>
 
 
//更改类MDCScopeManager
ScopeWrapper(Scope scope) {
    this.scope = scope;
    this.previousTraceId = lookup("trace_id");
    this.previousSpanId = lookup("span_id");
    this.previousSampled = lookup("trace_sampled");
 
    JaegerSpanContext ctx = (JaegerSpanContext) scope.span().context();
    // traceId的值由 Long.toHexString(ctx.getTraceId()) 改为 ctx.getTraceId()
    String traceId = Long.toHexString(ctx.getTraceId());
    String traceId = ctx.getTraceId();
 
    String spanId = Long.toHexString(ctx.getSpanId());
    String sampled = String.valueOf(ctx.isSampled());
 
    replace("trace_id", traceId);
    replace("span_id", spanId);
    replace("trace_sampled", sampled);
}
复制代码
原文  https://juejin.im/post/5dc23579f265da4d0d0dcf66
正文到此结束
Loading...