spring eureka security 批量更新失败,HTTP 状态码为 401
Posted
技术标签:
【中文标题】spring eureka security 批量更新失败,HTTP 状态码为 401【英文标题】:spring eureka security Batch update failure with HTTP status code 401 【发布时间】:2016-07-31 05:46:44 【问题描述】:我研究 spring cloud eureka , cloud 和它们工作得很好。但是在 eureka 服务中添加安全之后,它遇到了一些错误。
所有代码和错误详情都在https://github.com/keryhu/eureka-security
eureka 服务应用程序.yml
security:
user:
name: user
password: password
eureka:
client:
registerWithEureka: false
fetchRegistry: false
server:
wait-time-in-ms-when-sync-empty: 0
还有配置服务application.java
@SpringBootApplication
@EnableConfigServer
@EnableDiscoveryClient
配置服务应用程序.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
启动配置服务后导出错误:
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
【问题讨论】:
你可以试试 Brixton.RC2 吗? @spencergibb 我使用 Brixton.RC1 是的,请用RC2试试,如果还有问题,我们可以看看。 @spencergibb ,我已经更新到 RC2,但 eureka 仍然有Batch update failure with HTTP status code 401; discarding 1 replication tasks
...
你的eureka服务也需要设置安全serviceUrl
【参考方案1】:
我同意jacky-fan 的回答。
这些是我的工作配置在没有用户名和密码的情况下的样子。
服务器应用程序.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
客户端应用程序.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
【讨论】:
【参考方案2】:SET eureka.client.serviceUrl.defaultZone 的 eureka-server http://username:password@localhost:8761/eureka/
【讨论】:
我用用户名和密码试过了,还是一样的问题以上是关于spring eureka security 批量更新失败,HTTP 状态码为 401的主要内容,如果未能解决你的问题,请参考以下文章
学习SPRING BOOT, SPRING CLOUD之Eureka和security
学习Spring Cloud中eureka注册中心添加security认证,eureka client注册启动报错
Eureka Server增加Spring Security后的服务端和客户端配置
巨坑:spring cloud项目eureka添加security认证之后,client端注册失败
SpringCloud - Spring Cloud 之 Config分布式配置;Config注册至Eureka;集成 Security安全认证(十七)