spring-cloud / spring-cloud-commons

Common classes used in different Spring Cloud implementations
Apache License 2.0
701 stars 697 forks source link

Spring cloud bug with placeholders with comma in spring.profiles.include #1329

Open alex-kormukhin opened 6 months ago

alex-kormukhin commented 6 months ago

Describe the bug If we use placeholders with comma in spring.profiles.include (and spring.profiles.active) property like this: spring.profiles.include=${ENVIRONMENT_PROFILE_NAME:some_profile1,some_profile2}

vanilla spring boot application works fine: 2024-01-26_190115

but spring cloud application (with consul config, for example) with spring-cloud-starter-bootstrap (bootstrap mode) can't resolve such placeholders: 2024-01-26_190209

If also set spring.cloud.config.initialize-on-context-refresh=true cloud application crashes on start like this: `2024-01-26T19:28:33.299+03:00 ERROR 3808 --- [ main] o.s.boot.SpringApplication : Application run failed

org.springframework.cloud.consul.config.ConsulPropertySources$PropertySourceNotFoundException: java.lang.IllegalArgumentException: Illegal character in path at index 48: http://localhost:8500/v1/kv/config/application,${ENVIRONMENT_PROFILE_NAME:some_profile1/?recurse&token= at org.springframework.cloud.consul.config.ConsulPropertySources.createPropertySource(ConsulPropertySources.java:143) ~[spring-cloud-consul-config-4.1.0.jar:4.1.0] at org.springframework.cloud.consul.config.ConsulPropertySourceLocator.locate(ConsulPropertySourceLocator.java:88) ~[spring-cloud-consul-config-4.1.0.jar:4.1.0] at org.springframework.cloud.bootstrap.config.PropertySourceLocator.locateCollection(PropertySourceLocator.java:50) ~[spring-cloud-context-4.1.0.jar:4.1.0] at org.springframework.cloud.consul.config.ConsulPropertySourceLocator.locateCollection(ConsulPropertySourceLocator.java:71) ~[spring-cloud-consul-config-4.1.0.jar:4.1.0] at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.doInitialize(PropertySourceBootstrapConfiguration.java:120) ~[spring-cloud-context-4.1.0.jar:4.1.0] at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:110) ~[spring-cloud-context-4.1.0.jar:4.1.0] at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:627) ~[spring-boot-3.2.2.jar:3.2.2] at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:400) ~[spring-boot-3.2.2.jar:3.2.2] at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) ~[spring-boot-3.2.2.jar:3.2.2] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354) ~[spring-boot-3.2.2.jar:3.2.2] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-3.2.2.jar:3.2.2] at com.example.demo.DemoApplication.main(DemoApplication.java:10) ~[classes/:na] Caused by: java.lang.IllegalArgumentException: Illegal character in path at index 48: http://localhost:8500/v1/kv/config/application,${ENVIRONMENT_PROFILE_NAME:some_profile1/?recurse&token= at java.base/java.net.URI.create(URI.java:906) ~[na:na] at org.apache.http.client.methods.HttpGet.(HttpGet.java:66) ~[httpclient-4.5.14.jar:4.5.14] at com.ecwid.consul.transport.AbstractHttpTransport.makeGetRequest(AbstractHttpTransport.java:33) ~[consul-api-1.4.5.jar:na] at com.ecwid.consul.v1.ConsulRawClient.makeGetRequest(ConsulRawClient.java:139) ~[consul-api-1.4.5.jar:na] at com.ecwid.consul.v1.ConsulRawClient.makeGetRequest(ConsulRawClient.java:128) ~[consul-api-1.4.5.jar:na] at com.ecwid.consul.v1.kv.KeyValueConsulClient.getKVValues(KeyValueConsulClient.java:147) ~[consul-api-1.4.5.jar:na] at com.ecwid.consul.v1.ConsulClient.getKVValues(ConsulClient.java:644) ~[consul-api-1.4.5.jar:na] at org.springframework.cloud.consul.config.ConsulPropertySource.init(ConsulPropertySource.java:70) ~[spring-cloud-consul-config-4.1.0.jar:4.1.0] at org.springframework.cloud.consul.config.ConsulPropertySources.create(ConsulPropertySources.java:155) ~[spring-cloud-consul-config-4.1.0.jar:4.1.0] at org.springframework.cloud.consul.config.ConsulPropertySources.createPropertySource(ConsulPropertySources.java:134) ~[spring-cloud-consul-config-4.1.0.jar:4.1.0] ... 11 common frames omitted Caused by: java.net.URISyntaxException: Illegal character in path at index 48: http://localhost:8500/v1/kv/config/application,${ENVIRONMENT_PROFILE_NAME:some_profile1/?recurse&token= at java.base/java.net.URI$Parser.fail(URI.java:2974) ~[na:na] at java.base/java.net.URI$Parser.checkChars(URI.java:3145) ~[na:na] at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3227) ~[na:na] at java.base/java.net.URI$Parser.parse(URI.java:3175) ~[na:na] at java.base/java.net.URI.(URI.java:623) ~[na:na] at java.base/java.net.URI.create(URI.java:904) ~[na:na] ... 20 common frames omitted`

Also crashes when refresh Consul config by Consul KV change or by /actuator/refresh.

Spring boot 3.2.2, cloud 2023.0.0 (same as boot 2.7.18 and cloud 2021.0.9).

Look at PropertySourceBootstrapConfiguration.resolvePlaceholdersInProfiles: resolver first split by comma, then resolve placeholders.

Sample Vanilla boot application example: boot-app.zip

Cloud application example: cloud-app.zip