在对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服务,重启客户端就发现已经可以注册成功。

最新文章

  1. spring访问静态资源出错,No mapping found for HTTP request with URI xxx/resources/js/jquery.min.js...
  2. Xcode7中,如何新建category分类
  3. 温习SQL server
  4. HDU5441 Travel 并查集
  5. 书评<<剑指offer 名企面试官精讲典型编程题>>
  6. allegro使用汇总 [转贴]
  7. dede 5.7进后台卡死解决办法
  8. 【现代程序设计】【homework-07】
  9. 你晓得吗?大多数企业根本没有做到 DevOps!
  10. hadoop进不去web界面
  11. easyUI自带的时间插件日期选择、月份选择、时间选择的使用(转)
  12. RabbitMQ 消息队列 入门 第一章
  13. PHP算法学习(6) 单向链表 实现栈
  14. Plugin with id 'com.novoda.bintray-release' not found.的解决方案
  15. js中去掉字符串的空格、回车换行
  16. Unicode String to a UTF-8 TypedArray Buffer in JavaScript
  17. Nios II——定制自己的IP1之Nios接口类型
  18. 停止一个java的线程执行
  19. 深入理解Linux内核-系统调用
  20. 学霸网站之NABC

热门文章

  1. js回调函数(callback)(转载)
  2. Python接口测试-利用登录后的session用到登录后的接口中
  3. 性能测试 | 系统运行缓慢,CPU 100%,Full GC次数过多问题排查
  4. 安装win10提示“我们无法创建新的分区,也找不到现有分区”
  5. 怎么用php实现短信验证码发送
  6. CentOS 7 最小化安装后的注意事项
  7. [Kaggle] How to kaggle?
  8. Linux学习—maven安装
  9. Asp.net Core深入一:数据库访问(Mysql为例)
  10. LeetCode.1185-一周中的星期几(Day of the Week)