小埋社区

    • Login
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    说说我SpringCloud微服务碰到的神奇的坑

    编程
    java microservice
    2
    2
    451
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Bruce
      Bruce ACG last edited by

      最近在学微服务,学到Eureka注册中心的安全验证这一节时,按照文档的说法,先添加了spring-boot-starter-security依赖,然后在配置文件中设置了账号密码,并添加配置类用来忽略服务注册时的CSRF验证

      package org.bkcloud.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;
      
      @EnableWebSecurity
      public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
          @Override
          protected void configure(HttpSecurity http) throws Exception {
              http.csrf().ignoringAntMatchers("/eureka/**");
              super.configure(http);
          }
      }
      

      然后,当我的服务用账号密码注册到注册中心时,却提示

      com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server

      我花了几个小时各种改配置 ,重新启动,仍然无法解决。我甚至尝试过直接禁用CSRF防护,也没有效果。
      最终,我重启IDE,重新运行程序,问题莫名其妙就解决了


      总结

      此次问题

      • 原因:未知
      • 解决方法:未知
      • 感想:一脸懵逼
      1 Reply Last reply Reply Quote 0
      • a-wing
        a-wing last edited by

        学什么 Java 。赶快过来用 golang

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        © 2017-2022 小埋社区 All Rights Reserved | 皖ICP备17016228号-2