将所有使用springboot1.5版本改为springboot2.1.9,springcloud版本为Greenwich.SR3,springboot与springcloud版本对应关系表: start.spring.io/actuator/in…
由于1.5到2.0版本改动比较大,所以计划分步骤进行升级
升级 eureka,config比较顺利,改版本号后,就可以正常运行
gateway的过程比较曲折,以下为遇到的问题及解决方案
启动提示 org.springframework.cloud.netflix.zuul.filters.route.ZuulFallbackProvider 找不到
经过查询资料,原来新版本已经由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;
启动提示 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);
}
复制代码