Spring Cloud Greenwich 新特性和F版升级分享
发布日期:2021-06-29 22:13:38 浏览次数:2 分类:技术文章

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

640?wx_fmt=png

来源:https://dwz.cn/LkwPsmut

前几天介绍了,关于Spring Cloud Greenwich版本发布的官方博客翻译:,今天我们一起学习一下来自“冷冷gg”大神的升级战报!


2019.01.23 期待已久的Spring Cloud Greenwich 发布了release版本,作为我们团队也第一时间把RC版本替换为release,以下为总结,希望对你使用Spring Cloud Greenwich 有所帮助 Greenwich 只支持 Spring Boot 2.1.x 分支。如果使用 2.0.x 请使用Finchley版本。

pom坐标

主要是适配JAVA11

 
  1. <!--支持Spring Boot 2.1.X-->

  2. <dependency>

  3.    <groupId>org.springframework.boot</groupId>

  4.    <artifactId>spring-boot-dependencies</artifactId>

  5.    <version>2.1.2.RELEASE</version>

  6.    <type>pom</type>

  7.    <scope>import</scope>

  8. </dependency>

  9. <!--Greenwich.RELEASE-->

  10. <dependency>

  11.    <groupId>org.springframework.cloud</groupId>

  12.    <artifactId>spring-cloud-dependencies</artifactId>

  13.    <version>Greenwich.RELEASE</version>

  14.    <type>pom</type>

  15.    <scope>import</scope>

  16. </dependency>

升级netflix版本,DiscoveryClient支持获取InstanceId

640?wx_fmt=png

Spring Cloud Config 提供了新的存储介质

除了Git、File、JDBC,新版本提供 在Cloud Foundry的CredHub存储功能

 
  1. spring:

  2.  profiles:

  3.    active: credhub

  4.  cloud:

  5.    config:

  6.      server:

  7.        credhub:

  8.          url: https://credhub:8844

Spring Cloud Gateway

支持整合OAuth2

这里提供了一个例子: Spring Cloud Gateway and Spring Security OAuth2

整合的时候有个坑可以参考这个issue:ReactiveManagementWebSecurityAutoConfiguration Prevent's oauth2Login from being defaulted

新增重写响应头过滤器

 
  1. spring:

  2.  cloud:

  3.    gateway:

  4.      routes:

  5.      - id: rewriteresponseheader_route

  6.        uri: http://example.org

  7.        filters:

  8.        - RewriteResponseHeader=X-Response-Foo, , password=[^&]+, password=***

Feign的新特性和坑

@SpringQueryMap 对Get请求进行了增强

640?wx_fmt=png

  1. 终于解决这个问题了

  2. 不用直接使用OpenFeign新增的@QueryMap,由于缺少value属性 QueryMap注释与Spring不兼容...

异常解决

对Spring Cloud Finchley 进行直接升级时候发现feign启动报错了

 
  1. ***************************

  2. APPLICATION FAILED TO START

  3. ***************************

  4. Description:

  5. The bean 'pigx-upms-biz.FeignClientSpecification', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.

  6. Action:

  7. Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

  8. Process finished with exit code 1

  1. 第一种粗暴的解决方法,异常日志中说明了,在 bootstrap.yml中配置

 
  1. spring.main.allow-bean-definition-overriding=true

这是Spring Boot 2.1 后新增的属性运行bean 覆盖,不要配置到配置中心里面,不然无效

  1. 第二种,就是把通过同一个服务调用的代码,移动到同一个@FeignClient中

  2. contextId ,这个是@FeignClient 新增的一个属性

 
  1. This will be used as the bean name instead of name if present, but will not be used as a service id.

就可以用这个属性区分@FeigenClient 标志的同一个service 的接口

总结

  1. Spring Cloud F -- > G 变化很小,微乎其微主要是JAVA11的兼容

  2. 很遗憾没有看到 Spring Cloud Alibaba 加油。

  3. Spring Cloud LoadBalancer 还是老样子。目前来看暂时无法替代 Ribbon

  4. 欢迎加冷冷gg的Q2270033969,讨论Spring Cloud

本号正在连载「 Spring Cloud Alibaba基础教程 」

更多内容关注我,近期持续更新!

号外:最近整理了之前编写的一系列 Spring Boot 内容,做成了《Spring Boot基础教程》的PDF,关注我并回复:001 领取,002 资源即将整理出炉,随后将陆续奉上,敬请期待 640?wx_fmt=png

- END -

 近期热文:

640?wx_fmt=png

更多私货分享

欢迎加入「我的星球」

?

640?wx_fmt=png

看完,赶紧点个“好看”鸭

点鸭点鸭

↓↓↓↓

转载地址:https://didispace-wx.blog.csdn.net/article/details/86710373 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:PPT写得好的人,为什么都如此遭人痛恨?
下一篇:自身技术20K,offer 到手15K,为什么?

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2024年04月27日 03时34分21秒