001-Spring Cloud Edgware.SR3 升级最新 Finchley.SR1,spring boot 1.5.9.RELEASE 升级2.0.4.RELEASE注意问题点

一、前提

升级前 => 升级后

Spring Boot 1.5.x => Spring Boot 2.0.4.RELEASE

Spring Cloud Edgware SR3 => Spring Cloud Finchley.SR1

1.1、Eureka Server

ureka Server 依赖更新

升级前:

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

升级后:

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

1.2、Eureka Client

因为配置中心需要作为服务注册到注册中心,所以需要升级 Eureka Client,其他依赖没有变动。

Eureka Client 依赖更新

升级前:

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

升级后:

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

1.3、Spring Cloud

注册中心里面的客户端实例IP显示不正确

因为 Spring Cloud 获取服务客户端 IP 地址配置变更了。

升级前:

${spring.cloud.client.ipAddress}

升级后:

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

1.4、Spring Security

一般注册中心、配置中心都会使用安全加密,就会依赖 spring-boot-starter-security 组件,升级后有几个问题。

1.4.1、用户名和密码无法登录

因为 Spring Security 的参数进行了变更。

升级前:

security:
  user:
    name:
    password:

升级后:

spring:
  security:
     user:
       name:
       password:

1.4.2、使用security注册中心没有注册实例

如图所示,没有注册实例,两个注册中心无法互相注册。

因为 Spring Security 默认开启了所有 CSRF 攻击防御,需要禁用 /eureka 的防御。

在 Application 入口类增加忽略eureka配置:

package com.lhx.springcloud.discovery.configuration;

import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().ignoringAntMatchers("/eureka/**");
        super.configure(http);
    }
}

禁用全部

import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable();
    }
}

1.4.3、配置中心无法加解密

升级后发现访问配置中心无法读取到配置,也无法加解密配置信息,访问配置中心链接直接跳转到了登录页面。

现在想变回之前的 basic auth 认证方式,找源码发现是自动配置跳到了登录页面,现在重写一下。

自动配置源码:
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();
    }

}

其实就是把 formLogin() 干掉了,又回到之前的 basic auth 认证方式,如下图所示。

现在我们又可以使用以下命令加解密了。

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

恢复 basic auth 之后,之前的服务需要加密连接配置中心的又正常运行了。

1.5、Maven

升级到 Spring Boot 2.x 之后发现 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

Gateway 代替了 Zuul

原文地址:https://www.cnblogs.com/bjlhx/p/9445927.html

时间: 2024-08-29 07:10:20

001-Spring Cloud Edgware.SR3 升级最新 Finchley.SR1,spring boot 1.5.9.RELEASE 升级2.0.4.RELEASE注意问题点的相关文章

Spring Cloud Edgware SR3 让Zuul支持形如 /xxx和/xxx/yyy 格式的路径配置

在包路径:org.springframework.cloud.netflix.zuul.filters 下,新建类SimpleRouteLocator,取代jar包中的类.内容如下: 1 /* 2 * Copyright 2013-2014 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use

Spring Cloud 升级最新 Finchley 版本,踩了所有的坑!

Spring Boot 2.x 已经发布了很久,现在 Spring Cloud 也发布了 基于 Spring Boot 2.x 的 Finchley 版本,现在一起为项目做一次整体框架升级. 升级前 => 升级后 Spring Boot 1.5.x => Spring Boot 2.0.2 Spring Cloud Edgware SR4 => Spring Cloud Finchley.RELEASE Eureka Server Eureka Server 依赖更新 升级前: <

spring cloud:Edgware.RELEASE版本hystrix超时新坑

升级到Edgware.RELEASE发现,zuul中不管如何设置hystrix的超时时间均不起作用,仍然是默认的1000ms.  降回低版本后正常,但是低版本的fallback方法中,又拿不到详细异常信息,最终暂时在Edgware.RELEASE中,将hystrix的超时关掉,参考以下配置: ribbon: ReadTimeout: 5000 ConnectTimeout: 5000 MaxAutoRetries: 0 MaxAutoRetriesNextServer: 1 hystrix: c

Spring Cloud Alibaba发布第二个版本,Spring 发来贺电

还是熟悉的面孔,还是熟悉的味道,不同的是,这次的配方升级了. 今年10月底,Spring Cloud联合创始人Spencer Gibb在Spring官网的博客页面宣布:阿里巴巴开源 Spring Cloud Alibaba,并发布了首个预览版本.随后,Spring Cloud 官方Twitter也发布了此消息.- 传送门 时隔 51天,Spencer Gibb再次在Spring官网的博客页面宣布:Spring Cloud Alibaba发布了其开源后的第二个版本0.2.1,随后,Spring C

基于Spring Cloud的微服务构建学习-2 Spring Boot

基于Spring Cloud的微服务构建学习-2 Spring Boot 为什么使用Spring Boot而不是Spring Spring Boot具有自动化配置,快速开发,轻松部署优点,非常适合用作微服务架构中各项具体微服务的开发框架.它不仅可以帮助我们快速的构建微服务,还可以轻松简单的整合Spring Cloud实现系统服务化,而如果使用了传统的Spring构建方式的话,在整合过程中我们还需要做更多的依赖管理工作才能让它们完好的运行起来. Spring Boot的宗旨并非是重写Spring或

Spring Cloud(二):服务治理——Spring Cloud Eureka

服务治理是微服务架构中最为核心和基础的模块,主要作用是实现各个微服务实例的自动化注册和发现.Spring Cloud Eureka是Spring Cloud Netflix微服务套件中的一部分,基于Netflix EureKa做了二次封装,主要负责微服务架构中的服务治理功能. Eureka的服务发现包含两大组件,服务端发现组件(Eureka Server)和客户端发现组件(Eureka Client).服务端发现组件也被称为服务注册中心,主要提供了服务的注册功能,客户端发现组件主要用于处理服务的

springcloud --- spring cloud sleuth和zipkin日志管理(spring boot 2.18)

前言 在spring cloud分布式架构中,系统被拆分成了许多个服务单元,业务复杂性提高.如果出现了异常情况,很难定位到错误位置,所以需要实现分布式链路追踪,跟进一个请求有哪些服务参与,参与的顺序如何,从而去明确一个问题. spring cloud sleuth 通常来说,一个分布式服务跟踪系统主要由三部分:数据收集.数据存储和数据展示. 对于大规模的分布式系统来说,数据存储可分为实时数据和全量数据两部分.实时数据用来排查故障,全量数据用于系统优化:数据展示涉及数据挖掘和分析. 名词解释 服务

基于Spring Cloud的微服务构建学习-3 Spring Cloud Eureka配置详解

配置详解 在Eureka的服务治理体系中,主要分为服务端与客户端.服务端为服务注册中心,而客户端为各个提供接口的微服务应用.当部署高可用注册中心时,每个服务端也已经成为了客户端,因此,在使用Spring Cloud Eureka的过程中,我们所做的配置内容几乎都是对Eureka客户端配置进行的操作,所以了解这部分的配置内容,对于用好Eureka非常有帮助. 而Eureka服务端更多类似于一个现成产品,大多数情况下,我们不需要修改它的配置信息. Eureka客户端配置分类 服务注册相关配置,包括服

spring cloud实战与思考(一) spring config全局配置方案设计

"spring cloud"的配置中心工具"spring cloud config"提供了分布式系统配置文件集中管理解决方案.该工具功能强大,实现也很简单.网上可以搜索到很多开发教程和用例.本文并不是分享"spring cloud config"的开发方法,而是想聊一聊它的使用. 任何一个工具不管多么强大和便利,如果用的不好,也达不到期望的效果.拿到"spring cloud config"后,我期望基于这个工具构建的配置文件