1. 程式人生 > >Spring Cloud Greenwich 新特性和F升級分享

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

routes serve nts auto filters git ext exti eve

  2019.01.23 期待已久的Spring Cloud Greenwich 發布了release版本,作為我們團隊也第一時間把RC版本替換為release,以下為總結,希望對你使用Spring Cloud Greenwich 有所幫助 Greenwich 只支持 Spring Boot 2.1.x 分支。如果使用 2.0.x 請使用Finchley版本,
  
  pom坐標
  
  主要是適配JAVA11
  
  <!--支持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< www.ysyl157.com /artifactId>
  
  <version>Greenwich.RELEASE</version>
  
  <type>pom</type>
  
  <scope>import</scope>
  
  </dependency>
  
  升級netflix版本,DiscoveryClient支持獲取InstanceId
  
  image
  
  Spring Cloud Config 提供了新的存儲介質
  
  除了Git、File、JDBC,新版本提供 在Cloud Foundry的CredHub存儲功能
  
  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
  
  新增重寫響應頭過濾器
  
  spring:
  
  cloud:
  
  gateway:
  
  routes:
  
  - id: rewriteresponseheader_route
  
  uri: http://www.hengda157.com example.org
  
  filters:
  
  - RewriteResponseHeader=X-Response-Foo,www.dasheng178.com , password=[^&]+, password=***
  
  Feign 的新特性和坑
  
  @SpringQueryMap 對Get請求進行了增強
  
  終於解決這個問題了
  
  不用直接使用OpenFeign新增的@QueryMap,由於缺少value屬性 QueryMap註釋與Spring不兼容...
  
  異常解決
  
  對Spring Cloud Finchley 進行直接升級時候發現feign啟動報錯了
  
  ***************************
  
  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 www.wanchuang2.com overriding is disabled.
  
  Action:
  
  Consider renaming one of the beans or enabling overriding by setting spring.main.www.lezongyule.com allow-bean-definition-overriding=true
  
  Process finished with exit code 1
  
  第一種粗暴的解決方法,異常日誌中說明了,在 bootstrap.yml中配置
  
  spring.main.allow-bean-definition-overriding=true
  
  這是Spring Boot 2.1 後新增的屬性運行bean 覆蓋,不要配置到配置中心裏面,不然無效
  
  第二種,就是把通過同一個服務調用的代碼,移動到同一個@FeignClient中
  
  contextId ,這個是@FeignClient 新增的一個屬性
  
  This will be used as the bean name instead of name if present, but will not be used as a service id.
  
  就可以用這個屬性區分@FeigenClient 標誌的同一個service 的接口
  
  總結
  
  Spring Cloud F -- > G 變化很小,微乎其微主要是JAVA11的兼容
  
  很遺憾沒有看到 Spring Cloud Alibaba 加油。
  
  Spring Cloud LoadBalancer 還是老樣子。目前來看暫時無法替代 ribbon
  

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