码迷,mamicode.com
首页 > 其他好文 > 详细

客户端注册Cannot execute request on any known server解决

时间:2019-09-12 13:38:57      阅读:154      评论:0      收藏:0      [点我收藏+]

标签: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

一、官方文档

技术图片

 

 url: https://cloud.spring.io/spring-cloud-static/Finchley.SR2/multi/multi_spring-cloud-eureka-server.html#_securing_the_eureka_server

大意(英语不好,见谅):

只需通过Spring -boot-starter- security将Spring Security添加到服务路径中,就可以保护Eureka服务。默认情况下,当Spring Security位于类路径上时,它将要求在每次向应用程序发送请求时都发送一个有效的CSRF令牌。Eureka客户机通常不会拥有一个有效的跨站点请求伪造令牌(CSRF),您需要禁用/ Eureka /**端点的这个请求

2、添加配置文件

在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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!