Spring Could 2.0 eureka 配置spring.security后其他服务无法连接注册中心

 

Eureka的Server端和Client端成功启动,服务注册、发现都正常。但是在Client端向Server端请求注册服务时,需要验证用户名和密码,问题出现。

分析原因

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

解决步骤

  1. 添加继承类 WebSecurityConfigurerAdapter ;
  2. 启用 @EnableWebSecurity 注解;
  3. 覆盖父类的 configure(HttpSecurity http) 方法,禁用掉 csrf。
  4. 废话不多说,上图了

猜你喜欢

转载自blog.csdn.net/qq_38403092/article/details/81631064
今日推荐