淺談升級Spring Cloud到Finchley后的一點坑
最近為了使用Kotlin以及Webflux進行后臺應(yīng)用開發(fā),把Spring Cloud版本升級到了Finchley。
這種大版本的提升,坑自然是少不了的,我最近會把遇到問題都總結(jié)在這里避免大家花太多時間在排坑上:
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
這個參數(shù)已經(jīng)不能被識別了
我們來看看源碼:
# 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); }
發(fā)現(xiàn)原來的ipAddress已經(jīng)改為ip-address,那么我們在配置中心做相應(yīng)的改正即可。
注:改為ip-address不會對之前的老版本的項目產(chǎn)生影響,會自動解析并正確賦值
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
關(guān)于Java中的try-with-resources語句
這篇文章主要介紹了關(guān)于Java中的try-with-resources語句,try-with-resources是Java中的環(huán)繞語句之一,旨在減輕開發(fā)人員釋放try塊中使用的資源的義務(wù),需要的朋友可以參考下2023-05-05java多線程CyclicBarrier的使用案例,讓線程起步走
這篇文章主要介紹了java多線程CyclicBarrier的使用案例,讓線程起步走!具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-02-02在SpringBoot中集成H2數(shù)據(jù)庫的完整指南
Spring Boot是一個簡化企業(yè)級Java應(yīng)用程序開發(fā)的強大框架,H2數(shù)據(jù)庫是一個輕量級的、開源的SQL數(shù)據(jù)庫,非常適合用于開發(fā)和測試,本文將指導(dǎo)您如何在Spring Boot應(yīng)用程序中集成H2數(shù)據(jù)庫,并探索一些高級配置選項,需要的朋友可以參考下2024-10-10SpringBoot項目沒有把依賴的jar包一起打包的問題解決
這篇文章主要介紹了SpringBoot項目沒有把依賴的jar包一起打包的問題解決,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2019-09-09