坑一:Spring Cloud 2.0以上,eureka 开启登录验证后,eureka 客户端无法注册到eureka

升级Spring Cloud后,Eureka客户端无法注册到Eureka服务。原因是Spring Cloud 2.0以上默认启用csrf检验。解决方法是在Eureka Server端关闭csrf,通过自定义WebSecurityConfigurerAdapter并禁用csrf配置。
摘要由CSDN通过智能技术生成

之前用的Spring Cloud 是2.0以上的,开启eureka登录验证后,eureka客户端都能正常注册到eureka服务上

今天,升级Spring Cloud后,eureka客户端无法登录上。

查看日志:

原因分析

查资料了解到新版(Spring Cloud 2.0 以上)的security默认启用了csrf检验,要在eurekaServer端配置security的csrf检验为false

解决方法

  1. 添加一个继承 WebSecurityConfigurerAdapter 的类;
  2. 在类上添加 @EnableWebSecurity 注解;
  3. 覆盖父类的 configure(HttpSecurity http) 方法,关闭掉 csrf

示例代码

import org.springframework.context.annotation.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.w
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值