标签:desc boot code cloud stat package 应用程序 class xtend
在对eureka注册中心服务端添加安全验证后,新版本springcloud出现一个问题就是,在客户端注册到服务中心时报了一个错:Cannot execute request on any known server,重新仔细看了一下官方文档Securing The Eureka Server部分得以解决。
添加安全验证:https://www.cnblogs.com/zrk3/p/springcloud_securing_eurekaserver.html
大意(英语不好,见谅):
只需通过Spring -boot-starter- security将Spring Security添加到服务路径中,就可以保护Eureka服务。默认情况下,当Spring Security位于类路径上时,它将要求在每次向应用程序发送请求时都发送一个有效的CSRF令牌。Eureka客户机通常不会拥有一个有效的跨站点请求伪造令牌(CSRF),您需要禁用/ Eureka /**端点的这个请求
在eureka服务工程中添加配置文件:
package com.zrk.config; 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; /** * @Description: * @Author: zrk * @Date: 2019/9/12 */ @EnableWebSecurity class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.csrf().ignoringAntMatchers("/eureka/**"); super.configure(http); } }
重启eureka服务,重启客户端就发现已经可以注册成功。
客户端注册Cannot execute request on any known server解决
标签:desc boot code cloud stat package 应用程序 class xtend
原文地址:https://www.cnblogs.com/zrk3/p/springcloud_securing_bug.html