前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Spring Cloud Greenwich 新特性和F升级分享

Spring Cloud Greenwich 新特性和F升级分享

作者头像
冷冷
发布2019-05-26 20:07:09
4580
发布2019-05-26 20:07:09
举报
文章被收录于专栏:冷冷冷冷

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

pom坐标

主要是适配JAVA11

代码语言:javascript
复制
<!--支持Spring Boot 2.1.X-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-dependencies</artifactId>
	<version>2.1.2.RELEASE</version>
	<type>pom</type>
	<scope>import</scope>
</dependency>
<!--Greenwich.RELEASE-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-dependencies</artifactId>
    <version>Greenwich.RELEASE</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

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

image
image

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

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

代码语言:javascript
复制
spring:
  profiles:
    active: credhub
  cloud:
    config:
      server:
        credhub:
          url: https://credhub:8844

Spring Cloud Gateway

支持整合OAuth2

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

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

新增重写响应头过滤器

代码语言:javascript
复制
spring:
  cloud:
    gateway:
      routes:
      - id: rewriteresponseheader_route
        uri: http://example.org
        filters:
        - RewriteResponseHeader=X-Response-Foo, , password=[^&]+, password=***

Feign 的新特性和坑

@SpringQueryMap 对Get请求进行了增强

  1. 终于解决这个问题了
  2. 不用直接使用OpenFeign新增的@QueryMap,由于缺少value属性 QueryMap注释与Spring不兼容...

异常解决

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

代码语言:javascript
复制
***************************
APPLICATION FAILED TO START
***************************

Description:

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.

Action:

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


Process finished with exit code 1
  1. 第一种粗暴的解决方法,异常日志中说明了,在 bootstrap.yml中配置
代码语言:javascript
复制
spring.main.allow-bean-definition-overriding=true

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

  1. 第二种,就是把通过同一个服务调用的代码,移动到同一个@FeignClient中
  2. contextId ,这个是@FeignClient 新增的一个属性
代码语言:javascript
复制
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. 欢迎加我Q2270033969,讨论Spring Cloud ^_^
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • pom坐标
  • 升级netflix版本,DiscoveryClient支持获取InstanceId
  • Spring Cloud Config 提供了新的存储介质
  • Spring Cloud Gateway
    • 支持整合OAuth2
      • 新增重写响应头过滤器
      • Feign 的新特性和坑
        • @SpringQueryMap 对Get请求进行了增强
          • 异常解决
            • 总结
            相关产品与服务
            微服务引擎 TSE
            微服务引擎(Tencent Cloud Service Engine)提供开箱即用的云上全场景微服务解决方案。支持开源增强的云原生注册配置中心(Zookeeper、Nacos 和 Apollo),北极星网格(腾讯自研并开源的 PolarisMesh)、云原生 API 网关(Kong)以及微服务应用托管的弹性微服务平台。微服务引擎完全兼容开源版本的使用方式,在功能、可用性和可运维性等多个方面进行增强。
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档