spring-cloud-consul icon indicating copy to clipboard operation
spring-cloud-consul copied to clipboard

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

Open sergey-morenets opened this issue 5 years ago • 7 comments

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:

  • app
  • app,prod

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.

sergey-morenets avatar Jan 24 '21 10:01 sergey-morenets

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

spencergibb avatar Jan 27 '21 19:01 spencergibb

@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

sergey-morenets avatar Jan 27 '21 22:01 sergey-morenets

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

spencergibb avatar Jan 27 '21 22:01 spencergibb

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

sergey-morenets avatar Jan 27 '21 23:01 sergey-morenets

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.

spencergibb avatar Mar 08 '23 23:03 spencergibb

Hi @spencergibb

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

sergey-morenets avatar Mar 09 '23 07:03 sergey-morenets

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

spencergibb avatar Mar 09 '23 18:03 spencergibb