美文网首页
springCloud eureka客户端注册报 Cannot

springCloud eureka客户端注册报 Cannot

作者: yanshihao | 来源:发表于2020-11-23 15:44 被阅读0次

今天在学习springCloud入门时,eureka 客户端一直报错 Cannot execute request on any known server
发现新版springcloud在使用eureka时,集成了Spring Security。

在使用eureka时需要注意

服务方配置代码

server:
  port: 7001

eureka:
  instance:
    hostname: localhost             #Eureka服务端的实例名称
  client:
    register-with-eureka: false     #false表示不向注册中心注册自己
    fetch-registry: false           #false表示自己就是注册中心,职责就是维护服务实例,并不需要去检索服务
    service-url:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

spring:
  security:
    user:
      name: admin
      password: 123456

同时服务方需要关闭Security的CSRF配置,写配置类以关闭CSRF:

@EnableWebSecurity
class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().ignoringAntMatchers("/eureka/**");
        super.configure(http);
    }
}

客户端配置

eureka:
  client:
    service-url:
      defaultZone: http://admin:123456@localhost:7001/eureka/

相关文章

网友评论

      本文标题:springCloud eureka客户端注册报 Cannot

      本文链接:https://www.haomeiwen.com/subject/pxkviktx.html