好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

浅谈升级Spring Cloud到Finchley后的一点坑

最近为了使用kotlin以及webflux进行后台应用开发,把spring cloud版本升级到了finchley。

这种大版本的提升,坑自然是少不了的,我最近会把遇到问题都总结在这里避免大家花太多时间在排坑上:

failed to bind properties under ‘eureka.instance.instance-id' to java.lang.string:
description:

failed to bind properties under 'eureka.instance.instance-id' to java.lang.string:

    property: eureka.instance.instance-id
    value: ${spring.cloud.client.ipaddress}:${spring.application.name}:${spring.application.instance_id:${server.port}}
    origin: "eureka.instance.instance-id" from property source "bootstrapproperties"
    reason: could not resolve placeholder 'spring.cloud.client.ipaddress' in value "${spring.cloud.client.ipaddress}:${spring.application.name}:${spring.application.instance_id:${server.port}}"

spring.cloud.client.ipaddress 这个参数已经不能被识别了

我们来看看源码:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

# org.springframework.cloud.client.hostinfoenvironmentpostprocessor

 

@override

   public void postprocessenvironment(configurableenvironment environment,

       springapplication application) {

     inetutils.hostinfo hostinfo = getfirstnonloopbackhostinfo(environment);

     linkedhashmap<string, object> map = new linkedhashmap<>();

     map.put( "spring.cloud.client.hostname" , hostinfo.gethostname());

     map.put( "spring.cloud.client.ip-address" , hostinfo.getipaddress());

     mappropertysource propertysource = new mappropertysource(

         "springcloudclienthostinfo" , map);

     environment.getpropertysources().addlast(propertysource);

   }

发现原来的ipaddress已经改为ip-address,那么我们在配置中心做相应的改正即可。

注:改为ip-address不会对之前的老版本的项目产生影响,会自动解析并正确赋值

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

原文链接:https://blog.csdn.net/willflier/article/details/80360777

查看更多关于浅谈升级Spring Cloud到Finchley后的一点坑的详细内容...

  阅读:13次