日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

spring-cloud Finchley.SR2版本 升级微服务到springboot 2.0

發布時間:2025/3/20 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spring-cloud Finchley.SR2版本 升级微服务到springboot 2.0 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

讀書筆記 spring-cloud Finchley.SR2版本 升級微服務到springboot 2.0

貼碼云

https://gitee.com/imbobo_bo/angel-bo

碼云上的代碼已經升級完成

1. 修改 SpringBoot 依賴 到 2.0.6

<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.6.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent>

2. 修改 SpringCloud 依賴 到 Finchley.SR2

<dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>Finchley.SR2</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>

3. SpringCloud 版本兼容 SpringBoot

https://spring.io/projects/spring-cloud看這里

4. Eureka依賴變更

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency>

5. hystrix依賴變更

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId></dependency>

6. ribbon依賴變更

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-ribbon</artifactId></dependency>

7. zuul依賴變更

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-zuul</artifactId></dependency>

8. feigen依賴變更

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency>

9. center 變更

由原來的

security:user:name: angelpassword: angel

變為了

spring:security:user:name: angelpassword: angel

10. ErrorController 依賴變更

再處理全局異常時依賴變更

org.springframework.boot.autoconfigure.web.ErrorController; 變為 import org.springframework.boot.web.servlet.error.ErrorController;

11. Eureka 認證

You can secure your Eureka server simply by adding Spring Security to your server’s classpath via spring-boot-starter-security. By default when Spring Security is on the classpath it will require that a valid CSRF token be sent with every request to the app. Eureka clients will not generally possess a valid cross site request forgery (CSRF) token you will need to disable this requirement for the /eureka/**

CSRF認證配置,不認證注冊客戶端

@EnableWebSecurity class WebSecurityConfig extends WebSecurityConfigurerAdapter {@Overrideprotected void configure(HttpSecurity http) throws Exception {http.csrf().ignoringAntMatchers("/eureka/**");super.configure(http);} }

12. spring-boot-admin 接入

看這個就可以了,但一定對應上版本 http://codecentric.github.io/spring-boot-admin/2.0.4/#_what_is_spring_boot_admin

. 看SpringCloud總結

.1 @RefreshScope

刷新bean屬性

.2 @EnableDiscoveryClient

向注冊中心注冊服務,新版本可以自己實現 ServiceRegistry 向不同的注冊中心注冊,前提是要禁用自動注冊autoRegister=false

.3 Retrying Failed Requests

將Spring-Retry 引入到classpath中

client.ribbon.MaxAutoRetries,

client.ribbon.MaxAutoRetriesNextServer,

client.ribbon.OkToRetryOnAllOperations

這些屬性是關于retry的配置

*可以 spring.cloud.loadbalancer.retry.enabled=false 關閉這個功能*

.4 Ignore Network Interfaces

spring:cloud:inetutils:ignoredInterfaces:- docker0- veth.* spring:cloud:inetutils:preferredNetworks:- 192.168- 10.0 You can also force the use of only site-local addresses, as shown in the following example: .application.yml spring:cloud:inetutils:useOnlySiteLocalInterfaces: true

.5 Why Is It so Slow to Register a Service

eureka.instance.leaseRenewalIntervalInSeconds

可以通過這個屬性修改,小于30s 但堅持默認會更好,官網是這么說的

.6 在像Eureka注冊時 可以設置Zone

eureka.instance.metadataMap.zone = zone1

eureka.client.preferSameZoneEureka = true

可以通過設置zone 可以讓服務優先在同一個zone下查找

.7 ribbon 文檔

https://github.com/Netflix/ribbon/wiki/Working-with-load-balancers#components-of-load-balancer

.8 Using Ribbon with Eureka 這個不是很明白

.9 配置zuul

9.1 看例子

https://github.com/spring-cloud-samples/sample-zuul-filters

9.2 可以為路由加上正則表達式

@Bean public PatternServiceRouteMapper serviceRouteMapper() {return new PatternServiceRouteMapper("(?<name>^.+)-(?<version>v.+$)","${version}/${name}"); }

9.3 可以為路由配置指定服務器不加前綴

zuul:routes:users:path: /myusers/**stripPrefix: false

9.4 可以設置路由重試次數 retryable

If you set a default route (/), an application with @EnableZuulProxy could act as a standalone server. For example, zuul.route.home: / would route all traffic ("/**") to the "home" service.

9.5 如果設置default route (/) 則這個可以作為一個單獨的服務,接受請求

9.6 在設置路由時,如果需要有順序要求

zuul:routes:users:path: /myusers/**legacy:path: /**

9.7 要使用yaml配置,因為使用proterties時,順序是無效的

9.8 敏感信息

zuul:routes:users:path: /myusers/**sensitiveHeaders: Cookie,Set-Cookie,Authorizationurl: https://downstream

sensitiveHeaders: Cookie,Set-Cookie,Authorization 是默認的,不會轉發給下游服務 如果想向下游發送這些敏感信息,記得要清空這個 可以直接用zuul.sensitiveHeaders 設置全局的

9.9 zuul會增加一個默認的Endpoint

GET /routesGET /routes/details.

可以通過endpoints.routes.enabled 來禁用

9.10 上傳文件

有一個前綴 /zuul/*

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000 ribbon:ConnectTimeout: 3000ReadTimeout: 60000

9.11 設置zuul servlet 默認是 /zuul 可以通過 zuul.servlet-path 來設置

9.12 zuul 啟動時加載ribbon相關的上限文

zuul:ribbon:eager-load:enabled: true

.10 feign

@FeignClient(name = "stores", configuration = FooConfiguration.class) public interface StoreClient {//.. }

這樣可以讓當前feign客戶端使用配置,但是 這個FooConfiguration配置不能有@Configuration注解,否則會變成全局的配置,別切還不能唄@CompoentScan 或者其他注解掃描到

.11 fallbackFactory

@FeignClient(name = "hello", fallbackFactory = HystrixClientFallbackFactory.class) protected interface HystrixClient {@RequestMapping(method = RequestMethod.GET, value = "/hello")Hello iFailSometimes(); }@Component static class HystrixClientFallbackFactory implements FallbackFactory<HystrixClient> {@Overridepublic HystrixClient create(Throwable cause) {return new HystrixClient() {@Overridepublic Hello iFailSometimes() {return new Hello("fallback; reason was: " + cause.getMessage());}};} }

.12 feign logger

@Configuration public class FooConfiguration {@BeanLogger.Level feignLoggerLevel() {return Logger.Level.FULL;} }

轉載于:https://my.oschina.net/angelbo/blog/2996467

總結

以上是生活随笔為你收集整理的spring-cloud Finchley.SR2版本 升级微服务到springboot 2.0的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。