EUREKA开启密码保护后服务连接不上

spring boot 的版本是2.0.1 spring cloud的版本是Finchley.RC1

在实际开发中eureka需要进行登陆验证,在spring boot1.5.9的版本中直接引入依赖后就可以,但在spring boot 2.0.x以后eureka添加验证后出现了服务无法注册的问题,在在网上发现是因为erureka本身的安全校验问题。需要关闭csrf spring2.x版本的security默认启用了csrf检验,要在eurekaServer端配置security的csrf检验为false,代码如下

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();//关闭csrf

    super.configure(http);

    }

}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值