博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
springCloud升级到Finchley.RELEASE,SpringBoot升级到2.0.4
阅读量:4040 次
发布时间:2019-05-24

本文共 4855 字,大约阅读时间需要 16 分钟。

Spring cloud版本由Edgware.SR5升级到Finchley.RELEASE,Spring boot版本1.5.7升级到2.0.4,开启升级过程。

配置跟服务注册使用阿里的nacos,版本也由0.1.1升级到0.2.1。

 

  • org.springframework.cloud.netflix.feign.FeignClient

         引用路径为org.springframework.cloud.openfeign.FeignClient

 

  • org.springframework.cloud.netflix.feign.EnableFeignClients

        引用路径为org.springframework.cloud.openfeign.EnableFeignClients

  •  
org.hibernate.validator.constraints.NotBlank  
org.hibernate
hibernate-validator

上面的方法已过时,改为引用下面的包,同时路径改为

import javax.validation.constraints.NotNull;
org.hibernate.validator
hibernate-validator
6.1.0.Alpha4

如果校验,请求时需要加上@Validated

同时NotBlank的javax.validation.constraints.NotBlank 已过时,换成下面路径

javax.validation.constraints.NotBlank

更多validator的可以参考下面几个文章,增加拦截,统一捕获异常处理

 

  • org.springframework.cloud
    spring-cloud-starter-feign

starter-feign如果引用则指定版本,在2.0中没有starter的,我这边改为了

org.springframework.cloud
spring-cloud-starter-openfeign
  • org.springframework.cloud
    spring-cloud-starter-hystrix
    改为
    org.springframework.cloud
    spring-cloud-starter-netflix-hystrix

包路径加入了netflix公司

  • org.springframework.cloud
    spring-cloud-starter-zuul
    provided
    true
    改为
    org.springframework.cloud
    spring-cloud-starter-netflix-zuul
    provided
    true
  • RelaxedPropertyResolver  2.0舍弃,网上查到的都尝试过了,都不行。官网上也给出了说明

       改用自动注册Environment ,environment.getProperty进行读取配置赋值

@Autowiredprivate Environment environment;@PostConstruct    public void setEnvironment() {        this.url = environment.getProperty("spring.datasource.url");        this.userName= environment.getProperty("spring.datasource.username");        this.password = environment.getProperty("spring.datasource.password");        this.driveClassName = environment.getProperty("spring.datasource.driver-class-name");        this.filters = environment.getProperty("spring.datasource.filters");        this.maxActive = environment.getProperty("spring.datasource.maxActive");        this.initialSize = environment.getProperty("spring.datasource.initialSize");        this.maxWait = environment.getProperty("spring.datasource.maxWait");        this.minIdle = environment.getProperty("spring.datasource.minIdle");        this.timeBetweenEvictionRunsMillis = environment.getProperty("spring.datasource.timeBetweenEvictionRunsMillis");        this.minEvictableIdleTimeMillis = environment.getProperty("spring.datasource.minEvictableIdleTimeMillis");        this.validationQuery = environment.getProperty("spring.datasource.validationQuery");        this.testWhileIdle = environment.getProperty("spring.datasource.testWhileIdle");        this.testOnBorrow = environment.getProperty("spring.datasource.testOnBorrow");        this.testOnReturn = environment.getProperty("spring.datasource.testOnReturn");        this.poolPreparedStatements = environment.getProperty("spring.datasource.poolPreparedStatements");        this.maxOpenPreparedStatements = environment.getProperty("spring.datasource.maxOpenPreparedStatements");        this.typeAliasesPackage = environment.getProperty("mybatis.typeAliasesPackage");        this.xmlLocation = environment.getProperty("mybatis.xmlLocation");    }
  • nested exception is java.lang.BootstrapMethodError: java.lang.NoSuchMethodError: org.springframework.kafka.listener.config.ContainerProperties.setClientId(Ljava/lang/String;)

spring-boot-autoconfigure 2.0.4中KafkaAnnotationDrivenConfiguration引用ContainerProperties,

查看该方法中ContainerProperties中setClientId是从2.1.1版本开始,解决办法,升级Spring-Kafka的版本,kafka-clients可以保持不变。

  • redis RedisCacheManager 的初始化,Spring 缓存管理,spring2.0 跟Spring1.X版本的构造方法不一样

改为自定义配置代码,不用xml了

 

  • WebMvcConfigurerAdapter   类过时问题,2.0中官方推荐通过implements WebMvcConfigurer,还有一种办法是继承WebMvcConfigurationSupport(这个相对麻烦一些,需要override很多方法)修改是通过implements WebMvcConfigurer,修改哪一个,仅需实现具体方法就可以。如果修改了还不生效,那是因为没有加上@EnableWebMvc

同样的SwaggerConfiguration也implements WebMvcConfigurer,@EnableWebMvc,重写addResourceHandlers

 

  • java.sql.SQLFeatureNotSupportedException: 这个 org.postgresql.jdbc.PgConnection.createClob() 方法尚未被实作。

大意就是Hibernate要验证pgsql的一个方法,但是jdbc没有实现,但是这个错误呢并不影响,所以下面的方法把这块验证给屏蔽掉。参考

 

  • elasticsearch  org.elasticsearch.transport.TcpTransport.sendMessage(Ljava/lang/Object;Lorg/elasticsearch/common/bytes/BytesReference;Ljava/lang/Runnable;)

这个主要是jar包冲突的原因omitted for duplicate,下图中可以看到org.elasticsearch.client-transport中引入的netty4的版本5.6.10超过了本身transport的5.5.0

修改办法:显示引入netty,同时exclusion transport中的netty

 

-------------------至此,所有的module全部成功启动成功,全部注册到nacos中了--------------------------

转载地址:http://tgadi.baihongyu.com/

你可能感兴趣的文章
linux不同模块completion通信
查看>>
linux printf获得时间戳
查看>>
C语言位扩展
查看>>
linux dump_backtrace
查看>>
linux irqdebug
查看>>
git 常用命令
查看>>
linux位操作API
查看>>
uboot.lds文件分析
查看>>
uboot start.s文件分析
查看>>
没有路由器的情况下,开发板,虚拟机Ubuntu,win10主机,三者也可以ping通
查看>>
本地服务方式搭建etcd集群
查看>>
安装k8s Master高可用集群
查看>>
忽略图片透明区域的事件(Flex)
查看>>
忽略图片透明区域的事件(Flex)
查看>>
AS3 Flex基础知识100条
查看>>
Flex动态获取flash资源库文件
查看>>
Flex 中的元数据标签
查看>>
flex4 中创建自定义弹出窗口
查看>>
01Java基础语法-13. if分支语句的灵活使用
查看>>
01Java基础语法-15.for循环结构
查看>>