最近為了使用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