spring eureka security使用HTTP状态码401批量更新失败

时间:2016-04-10 03:26:42

标签: spring spring-security spring-cloud netflix-eureka spring-cloud-netflix

我研究春云尤里卡,云,他们工作得很好。但在eureka服务中添加安全性后,它遇到了一些错误。

所有代码和错误详情均在https://github.com/keryhu/eureka-security

eureka service application.yml

security:
  user:
    name: user
    password: password

eureka: 
  client:
    registerWithEureka: false
    fetchRegistry: false
  server:
    wait-time-in-ms-when-sync-empty: 0 

和config-service application.java

@SpringBootApplication
@EnableConfigServer
@EnableDiscoveryClient

config-service application.yml

eureka:
  client:
    registry-fetch-interval-seconds: 5
    serviceUrl:
       defaultZone: http://user:password@${domain.name:localhost}:8761/eureka/

spring:  
  cloud:
     config:
       server:
         git:
           uri: https://github.com/spring-cloud-samples/config-repo
           basedir: target/config 
  

启动config-service后导出错误:

2016-04-10 11:22:39.402 ERROR 80526 --- [get_localhost-3] c.n.e.cluster.ReplicationTaskProcessor   : Batch update failure with HTTP status code 401; discarding 1 replication tasks
2016-04-10 11:22:39.402  WARN 80526 --- [get_localhost-3] c.n.eureka.util.batcher.TaskExecutors    : Discarding 1 tasks of TaskBatchingWorker-target_localhost-3 due to permanent error
2016-04-10 11:23:09.411 ERROR 80526 --- [get_localhost-3] c.n.e.cluster.ReplicationTaskProcessor   : Batch update failure with HTTP status code 401; discarding 1 replication tasks
2016-04-10 11:23:09.412  WARN 80526 --- [get_localhost-3] c.n.eureka.util.batcher.TaskExecutors    : Discarding 1 tasks of TaskBatchingWorker-target_localhost-3 due to permanent error
2016-04-10 11:23:39.429 ERROR 80526 --- [get_localhost-3] c.n.e.cluster.ReplicationTaskProcessor   : Batch update failure with HTTP status code 401; discarding 1 replication tasks
2016-04-10 11:23:39.430  WARN 80526 --- [get_localhost-3] c.n.eureka.util.batcher.TaskExecutors    : Discarding 1 tasks of TaskBatchingWorker-target_localhost-3 due to permanent error

2 个答案:

答案 0 :(得分:2)

设置eureka-server的eureka.client.serviceUrl.defaultZone http://username:password@localhost:8761/eureka/

答案 1 :(得分:-1)

我同意jacky-fan回答。

这些是我的工作配置在没有用户名和密码的情况下的样子。

server application.yml

spring:
  application:
    name: eureka-service
server:
  port: 8302
eureka:
  client:
    register-with-eureka: false 
    fetch-registry: false
    service-url:
      defaultZone: http://localhost:8302/eureka/
  server:
    wait-time-in-ms-when-sync-empty: 0   

客户端application.yml

eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://localhost:8302/eureka/
  instance:
    hostname: localhost
spring:
  application:
    name: my-service
server:
  port: 8301