zoukankan      html  css  js  c++  java
  • 解决eureka集群报错Root name 'timestamp' does not match expected ('instance')

    最近搭建eureka集群注册中心时,单机版的没有问题,但是在搭建集群版时,项目启动后报错:

    Root name 'timestamp' does not match expected ('instance')

    因为我给eureka添加了登录认证,所以每个节点在相互注册时需要加上用户名和密码,配置如下:
    server.port=7902
    spring.application.name=eureka
    
    #安全中心配置登录用户名密码
    spring.security.user.name=root
    spring.security.user.password=root
    
    #注册中心配置
    #禁止自己当做服务注册  禁止自己注册自己 集群模式时需要允许互相注册
    #eureka.client.register-with-eureka = false
    #屏蔽注册信息   集群模式时不能屏蔽
    #eureka.client.fetch-registry = false
    
    eureka.instance.hostname= eureka-7902
    eureka.client.service-url.defaultZone = http://root:root@eureka-7901:7901/eureka/,http://root:root@eureka-7903:7903/eureka/
    

      

      配置中的 http://root:root@eureka-7901:7901/eureka/
      这种路径,是eureka所支持的认证地址url,添加了安全认证后,集群的注册地址就需要按照这格式写:http://username:password@hostname:port/eureka/
      但是添加了认证后,集群在相互注册时,就会出现这个错误:Root name 'timestamp' does not match expected ('instance')
    查了好久才知道,集群方式需要关闭spring的csrf认证才行,单独写一个配置类,将csrf认证设置为关闭即可,代码如下:
    /**
     * csrf配置类
     *
     * @author Zhangzhiyong
     * @date 2021/7/23 16:29
     */
    @EnableWebSecurity
    @Configuration
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
        
        @Override
        public void configure(HttpSecurity http) throws Exception {
            http.csrf().disable();//关闭csrf认证,否则会报错Root name 'timestamp' does not match expected ('instance')
            super.configure(http);
        }
    }
    

      然后eureka集群就可以正常运行了。

  • 相关阅读:
    线性回归问题
    聚类:层次聚类
    聚类:(K-means)算法
    神经网络算法
    AutoEventWireup解释
    asp.net中runat="server"的含义
    十步完全理解SQL
    sqlserver中分区函数 partition by的用法
    被忽略却很有用的html标签
    net中使用母版页
  • 原文地址:https://www.cnblogs.com/zhangzhiyong-/p/15062375.html
Copyright © 2011-2022 走看看