日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

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

發(fā)布時(shí)間:2025/3/20 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spring-cloud Finchley.SR2版本 升级微服务到springboot 2.0 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>

讀書(shū)筆記 spring-cloud Finchley.SR2版本 升級(jí)微服務(wù)到springboot 2.0

貼碼云

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

碼云上的代碼已經(jīng)升級(jí)完成

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 變更

由原來(lái)的

security:user:name: angelpassword: angel

變?yōu)榱?/p> spring:security:user:name: angelpassword: angel

10. ErrorController 依賴變更

再處理全局異常時(shí)依賴變更

org.springframework.boot.autoconfigure.web.ErrorController; 變?yōu)?import org.springframework.boot.web.servlet.error.ErrorController;

11. Eureka 認(rèn)證

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認(rèn)證配置,不認(rèn)證注冊(cè)客戶端

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

12. spring-boot-admin 接入

看這個(gè)就可以了,但一定對(duì)應(yīng)上版本 http://codecentric.github.io/spring-boot-admin/2.0.4/#_what_is_spring_boot_admin

. 看SpringCloud總結(jié)

.1 @RefreshScope

刷新bean屬性

.2 @EnableDiscoveryClient

向注冊(cè)中心注冊(cè)服務(wù),新版本可以自己實(shí)現(xiàn) ServiceRegistry 向不同的注冊(cè)中心注冊(cè),前提是要禁用自動(dòng)注冊(cè)autoRegister=false

.3 Retrying Failed Requests

將Spring-Retry 引入到classpath中

client.ribbon.MaxAutoRetries,

client.ribbon.MaxAutoRetriesNextServer,

client.ribbon.OkToRetryOnAllOperations

這些屬性是關(guān)于retry的配置

*可以 spring.cloud.loadbalancer.retry.enabled=false 關(guān)閉這個(gè)功能*

.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

可以通過(guò)這個(gè)屬性修改,小于30s 但堅(jiān)持默認(rèn)會(huì)更好,官網(wǎng)是這么說(shuō)的

.6 在像Eureka注冊(cè)時(shí) 可以設(shè)置Zone

eureka.instance.metadataMap.zone = zone1

eureka.client.preferSameZoneEureka = true

可以通過(guò)設(shè)置zone 可以讓服務(wù)優(yōu)先在同一個(gè)zone下查找

.7 ribbon 文檔

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

.8 Using Ribbon with Eureka 這個(gè)不是很明白

.9 配置zuul

9.1 看例子

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

9.2 可以為路由加上正則表達(dá)式

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

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

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

9.4 可以設(shè)置路由重試次數(shù) 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 如果設(shè)置default route (/) 則這個(gè)可以作為一個(gè)單獨(dú)的服務(wù),接受請(qǐng)求

9.6 在設(shè)置路由時(shí),如果需要有順序要求

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

9.7 要使用yaml配置,因?yàn)槭褂胮roterties時(shí),順序是無(wú)效的

9.8 敏感信息

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

sensitiveHeaders: Cookie,Set-Cookie,Authorization 是默認(rèn)的,不會(huì)轉(zhuǎn)發(fā)給下游服務(wù) 如果想向下游發(fā)送這些敏感信息,記得要清空這個(gè) 可以直接用zuul.sensitiveHeaders 設(shè)置全局的

9.9 zuul會(huì)增加一個(gè)默認(rèn)的Endpoint

GET /routesGET /routes/details.

可以通過(guò)endpoints.routes.enabled 來(lái)禁用

9.10 上傳文件

有一個(gè)前綴 /zuul/*

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

9.11 設(shè)置zuul servlet 默認(rèn)是 /zuul 可以通過(guò) zuul.servlet-path 來(lái)設(shè)置

9.12 zuul 啟動(dòng)時(shí)加載ribbon相關(guān)的上限文

zuul:ribbon:eager-load:enabled: true

.10 feign

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

這樣可以讓當(dāng)前feign客戶端使用配置,但是 這個(gè)FooConfiguration配置不能有@Configuration注解,否則會(huì)變成全局的配置,別切還不能唄@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;} }

轉(zhuǎn)載于:https://my.oschina.net/angelbo/blog/2996467

總結(jié)

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

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。