解决eureka集群报错Root name 'timestamp' does not match expected ('instance')

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

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

因为我给eureka添加了登录认证,所以每个节点在相互注册时需要加上用户名和密码,配置如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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/

  

1
配置中的 http://root:root@eureka-7901:7901/eureka/
1
这种路径,是eureka所支持的认证地址url,添加了安全认证后,集群的注册地址就需要按照这格式写:http://username:password@hostname:port/eureka/
  但是添加了认证后,集群在相互注册时,就会出现这个错误:Root name 'timestamp' does not match expected ('instance')
查了好久才知道,集群方式需要关闭spring的csrf认证才行,单独写一个配置类,将csrf认证设置为关闭即可,代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
 * 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集群就可以正常运行了。

posted @   张志勇-  阅读(3110)  评论(1编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示