1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      SpringCloud升級最新Finchley版本的坑有哪些-創(chuàng)新互聯(lián)

      這篇文章給大家分享的是有關(guān)Spring Cloud升級最新Finchley版本的坑有哪些的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

      創(chuàng)新互聯(lián)從2013年開始,先為昌寧等服務(wù)建站,昌寧等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為昌寧企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

      Spring Boot 2.x 已經(jīng)發(fā)布了很久,現(xiàn)在 Spring Cloud 也發(fā)布了 基于 Spring Boot 2.x 的 Finchley 版本,現(xiàn)在一起為項(xiàng)目做一次整體框架升級。

      升級前 => 升級后

      Spring Boot 1.5.x => Spring Boot 2.0.2

      Spring Cloud Edgware SR4 => Spring Cloud Finchley.RELEASE

      Eureka Server

      Eureka Server 依賴更新

      升級前:

      
        org.springframework.cloud
        spring-cloud-starter-eureka-server
      

      升級后:

      
        org.springframework.cloud
        spring-cloud-starter-netflix-eureka-server
      

      Eureka Client

      因?yàn)榕渲弥行男枰鳛榉?wù)注冊到注冊中心,所以需要升級 Eureka Client,其他依賴沒有變動。

      Eureka Client 依賴更新

      升級前:

      
        org.springframework.cloud
        spring-cloud-starter-eureka
      

      升級后:

      
        org.springframework.cloud
        spring-cloud-starter-netflix-eureka-client
      

      Spring Cloud

      注冊中心里面的客戶端實(shí)例IP顯示不正確

      因?yàn)?Spring Cloud 獲取服務(wù)客戶端 IP 地址配置變更了。

      升級前:

      ${spring.cloud.client.ipAddress}

      升級后:

      ${spring.cloud.client.ip-address}

      Spring Security

      一般注冊中心、配置中心都會使用安全加密,就會依賴 spring-boot-starter-security 組件,升級后有幾下兩個問題。

      1、用戶名和密碼無法登錄

      因?yàn)?Spring Security 的參數(shù)進(jìn)行了變更。

      升級前:

      security:
       user:
        name:
        password:

      升級后:

      spring:
       security:
         user:
          name: 
          password:

      2、注冊中心沒有注冊實(shí)例

      如圖所示,沒有注冊實(shí)例,兩個注冊中心無法互相注冊。

      Spring Cloud升級最新Finchley版本的坑有哪些

      因?yàn)?Spring Security 默認(rèn)開啟了所有 CSRF 攻擊防御,需要禁用 /eureka 的防御。

      在 Application 入口類增加忽略配置:

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

      3、配置中心無法加解密

      升級后發(fā)現(xiàn)訪問配置中心無法讀取到配置,也無法加解密配置信息,訪問配置中心鏈接直接跳轉(zhuǎn)到了登錄頁面。

      Spring Cloud升級最新Finchley版本的坑有哪些

      現(xiàn)在想變回之前的 basic auth 認(rèn)證方式,找源碼發(fā)現(xiàn)是自動配置跳到了登錄頁面,現(xiàn)在重寫一下。

      自動配置源碼:
      org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter#configure(org.springframework.security.config.annotation.web.builders.HttpSecurity)

      protected void configure(HttpSecurity http) throws Exception {
        logger.debug("Using default configure(HttpSecurity). If subclassed this will potentially override subclass configure(HttpSecurity).");
      
        http
          .authorizeRequests()
            .anyRequest().authenticated()
            .and()
          .formLogin().and()
          .httpBasic();
      }

      重寫之后:

      @EnableWebSecurity
      static class WebSecurityConfig extends WebSecurityConfigurerAdapter {
      
        @Override
        protected void configure(HttpSecurity http) throws Exception {
          http.csrf().ignoringAntMatchers("/**").and().authorizeRequests().anyRequest()
              .authenticated().and().httpBasic();
        }
      
      }

      其實(shí)就是把 formLogin() 干掉了,又回到之前的 basic auth 認(rèn)證方式,如下圖所示。

      Spring Cloud升級最新Finchley版本的坑有哪些

      現(xiàn)在我們又可以使用以下命令加解密了。

      如解密:
      curl http://xx.xx.xx.xx:7100/decrypt -d secret -u user:password

      恢復(fù) basic auth 之后,之前的服務(wù)需要加密連接配置中心的又正常運(yùn)行了。

      Maven

      升級到 Spring Boot 2.x 之后發(fā)現(xiàn) Spring Boot 的 Maven 啟動插件不好用了,主要是 Profile 不能自由切換。

      升級前:

      spring-boot:run -Drun.profiles=profile1

      升級后:

      spring-boot:run -Dspring-boot.run.profiles=profile1

      具體的請參考:https://docs.spring.io/spring-boot/docs/current/maven-plugin/run-mojo.html

      Failed to bind properties under ‘eureka.instance.instance-id' to java.lang.String:

      Description:
      
      Failed to bind properties under 'eureka.instance.instance-id' to java.lang.String:
      
      Property: eureka.instance.instance-id
      Value: ${spring.cloud.client.ipAddress}:${spring.application.name}:${spring.application.instance_id:${server.port}}
      Origin: "eureka.instance.instance-id" from property source "bootstrapProperties"
      Reason: Could not resolve placeholder 'spring.cloud.client.ipAddress' in value "${spring.cloud.client.ipAddress}:${spring.application.name}:${spring.application.instance_id:${server.port}}"

      spring.cloud.client.ipAddress這個參數(shù)已經(jīng)不能被識別了

      我們來看看源碼:

      # org.springframework.cloud.client.HostInfoEnvironmentPostProcessor
      
      @Override
      public void postProcessEnvironment(ConfigurableEnvironment environment,
      SpringApplication application) {
      InetUtils.HostInfo hostInfo = getFirstNonLoopbackHostInfo(environment);
      LinkedHashMap map = new LinkedHashMap<>();
      map.put("spring.cloud.client.hostname", hostInfo.getHostname());
      map.put("spring.cloud.client.ip-address", hostInfo.getIpAddress());
      MapPropertySource propertySource = new MapPropertySource(
      "springCloudClientHostInfo", map);
      environment.getPropertySources().addLast(propertySource);
      }

      發(fā)現(xiàn)原來的ipAddress已經(jīng)改為ip-address,那么我們在配置中心做相應(yīng)的改正即可。

      注:改為ip-address不會對之前的老版本的項(xiàng)目產(chǎn)生影響,會自動解析并正確賦值

      感謝各位的閱讀!關(guān)于“Spring Cloud升級最新Finchley版本的坑有哪些”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!


      新聞標(biāo)題:SpringCloud升級最新Finchley版本的坑有哪些-創(chuàng)新互聯(lián)
      標(biāo)題來源:http://ef60e0e.cn/article/hiecc.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        上林县| 四会市| 汉中市| 镇原县| 阿勒泰市| 四平市| 定兴县| 内黄县| 当阳市| 和龙市| 叶城县| 南安市| 临西县| 孝义市| 玉林市| 政和县| 怀宁县| 杭锦后旗| 垣曲县| 聂荣县| 繁峙县| 洪泽县| 河西区| 石台县| 靖宇县| 苍梧县| 申扎县| 淮南市| 宜良县| 怀仁县| 崇信县| 乾安县| 兴业县| 钦州市| 永兴县| 建阳市| 福建省| 太谷县| 三穗县| 同心县| 滕州市|