Failed to bind properties under 'eureka.client.service-url' to java.util.Map<java.lang.String, java.lang.String>

本文将介绍怎样解决 Failed to bind properties under 'eureka.client.service-url' to java.util.Map<java.lang.String, java.lang.String> 错误

今天在学习 Spring Cloud 的 Ribbon 的时候,搭建的 Eureka client 启动失败,错误堆栈信息如下:

2021-03-09 12:58:42.826 ERROR 8032 --- [  restartedMain] o.s.b.web.embedded.tomcat.TomcatStarter  : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration': Unsatisfied dependency expressed through field 'eurekaServerConfig'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'eurekaServerConfig' defined in class path resource [org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration$EurekaServerConfigBeanConfiguration.class]: Unsatisfied dependency expressed through method 'eurekaServerConfig' parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'eurekaClientConfigBean': Could not bind properties to 'EurekaClientConfigBean' : prefix=eureka.client, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'eureka.client.service-url' to java.util.Map<java.lang.String, java.lang.String>
2021-03-09 12:58:42.874  INFO 8032 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-03-09 12:58:42.886  WARN 8032 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2021-03-09 12:58:42.917  INFO 8032 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-03-09 12:58:42.945 ERROR 8032 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:
Failed to bind properties under 'eureka.client.service-url' to java.util.Map<java.lang.String, java.lang.String>:
    Reason: No converter found capable of converting from type [java.lang.String] to type [java.util.Map<java.lang.String, java.lang.String>]
Action:
Update your application's configuration

Process finished with exit code 0

我的配置文件如下:

eureka:
  instance:
    hostname: localhost
  client:
    # 不向注册中心注册自己
    register-with-eureka: false
    # 取消检索服务
    fetch-registry: false
    # 启动独立模式的Eureka server
    # 关闭客户端行为,这样它就不会不断尝试并无法到达它的对等端
    # defaultZone 默认使用 http://localhost:8761/eureka/ 地址
    # 使 serviceUrl 指向与本地实例相同的主机
    service-url: http://${eureka.instance.hostname}:${server.port}/eureka/
  server:
    # 开启注册中心的保护机制,默认是开启
    enable-self-preservation: true
    # 设置保护机制的阈值,默认是0.85
    renewal-percent-threshold: 0.5

仔细查看配置发现,是因为 service-url  配置存在问题,应该在 service-url 下面创建一个 defaultZone 项。修改后的配置:

eureka:
  instance:
    hostname: localhost
  client:
    # 不向注册中心注册自己
    register-with-eureka: false
    # 取消检索服务
    fetch-registry: false
    # 启动独立模式的Eureka server
    # 关闭客户端行为,这样它就不会不断尝试并无法到达它的对等端
    # defaultZone 默认使用 http://localhost:8761/eureka/ 地址
    # 使 serviceUrl 指向与本地实例相同的主机
    service-url:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
  server:
    # 开启注册中心的保护机制,默认是开启
    enable-self-preservation: true
    # 设置保护机制的阈值,默认是0.85
    renewal-percent-threshold: 0.5
天赋如同自然花木,要用学习来修剪。 —— 培根
0 不喜欢
说说我的看法 -
全部评论(
没有评论
关于
本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,请来信告知:hxstrive@outlook.com
公众号