spring-cloud / spring-cloud-consul

Spring Cloud Consul
http://cloud.spring.io/spring-cloud-consul/
Apache License 2.0
813 stars 541 forks source link

Commas in spring.config.import split config data location rather than act as profile separator #701

Open sergey-morenets opened 3 years ago

sergey-morenets commented 3 years ago

Hi

I tried to use Spring Config Import feature that appeared in Spring Boot 2.4. It works fine without Spring profiles but if I tried to use a profile then errors are present.

The documentation for Spring Cloud Consul Config states that if you want to use profiles you should create similar folders structure in Consul:

config/testApp,dev/
config/testApp/
config/application,dev/
config/application/

I want to use default and prod profiles in my Spring Boot application. So I created two root folders in Consul:

If I try to specify app and app,prod folder in my application-prod.yml:

spring:
  config:
    import: "consul:localhost:8500;app;app,prod"

Then I get the exceptions:

java.lang.IllegalStateException: Unable to load config data from 'prod'
    at org.springframework.boot.context.config.StandardConfigDataLocationResolver.getReferences(StandardConfigDataLocationResolver.java:125)
Caused by: java.lang.IllegalStateException: File extension is not known to any PropertySourceLoader. If the location is meant to reference a directory, it must end in '/'
    at org.springframework.boot.context.config.StandardConfigDataLocationResolver.getReferencesForFile(StandardConfigDataLocationResolver.java:200)
    at org.springframework.boot.context.config.StandardConfigDataLocationResolver.getReferences(StandardConfigDataLocationResolver.java:122)

If omit the last folder:

spring:
  config:
    import: "consul:localhost:8500;app"

then configuration is loaded properly. Please advise on this issue.

spencergibb commented 3 years ago

I believe this was fixed as part of https://github.com/spring-cloud/spring-cloud-consul/issues/693. Can you verify with snapshots?

sergey-morenets commented 3 years ago

@spencergibb I just upgraded Spring Cloud Consul version in my project to 3.0.2-SNAPSHOT but still got the same exception during startup:


java.lang.IllegalStateException: Unable to load config data from 'prod'
    at org.springframework.boot.context.config.StandardConfigDataLocationResolver.getReferences(StandardConfigDataLocationResolver.java:128)
    at org.springframework.boot.context.config.StandardConfigDataLocationResolver.resolve(StandardConfigDataLocationResolver.java:115)

Caused by: java.lang.IllegalStateException: File extension is not known to any PropertySourceLoader. If the location is meant to reference a directory, it must end in '/'
    at org.springframework.boot.context.config.StandardConfigDataLocationResolver.getReferencesForFile(StandardConfigDataLocationResolver.java:214)
    at org.springframework.boot.context.config.StandardConfigDataLocationResolver.getReferences(StandardConfigDataLocationResolver.java:125)
    ... 30 common frames omitted
spencergibb commented 3 years ago

I only get that if spring-cloud-starter-consul-config is not on the classpath. Can you provide your pom.xml or build.gradle?

sergey-morenets commented 3 years ago

I only get that if spring-cloud-starter-consul-config is not on the classpath. Can you provide your pom.xml or build.gradle?

Yes, sure. I committed my demo project: https://github.com/sergey-morenets/spring-cloud-consul-config-demo I got an exception if run the project: mvn spring-boot:run

spencergibb commented 1 year ago

Sorry for the delay. Spring Boot is splitting the property on the comma. I'm afraid I can't do much about that. Maybe setting the profile separator to something else.

sergey-morenets commented 1 year ago

Hi @spencergibb

In fact, you can do a lot, for example, update the documentation and point out this case.

spencergibb commented 1 year ago

Yes, we can update the docs. Thanks for the suggestion. I only meant I couldn't fix the issue on our side.