'Unable to configure Spring Cloud Consul for specific profiles

I'm trying to configure spring cloud consul for a specific profile but when I try to run the application I get the following error:

***************************
APPLICATION FAILED TO START
***************************

Description:

Config data location 'consul:' does not exist

Action:

Check that the value 'consul:' at class path resource [application-local.properties] - 6:22 is correct, or prefix it with 'optional:'


Process finished with exit code 1

If I update spring.config.import to spring.config.import=optional:consul: in application-local.properties, consul configuration is ignored and the configuration from the properties file is used instead of consul.

application.properties:

spring.cloud.consul.enabled=false

application-local.properties:

spring.cloud.consul.enabled=true
spring.config.import=consul:

spring.cloud.consul.config.enabled=true
spring.cloud.consul.config.watch.enabled=true
spring.cloud.consul.config.watch.delay=6000
spring.cloud.consul.config.watch.wait-time=1
spring.cloud.consul.config.profile-separator=_

It seems that Spring is not overriding the default configuration with the one specified in application-local.properties. I also tried configuring consul in bootstrap.properties and bootstrap-local.properties but I got the following error:

***************************
APPLICATION FAILED TO START
***************************

Description:

No spring.config.import property has been defined

Action:

Add a spring.config.import=consul: property to your configuration.
    If configuration is not required add spring.config.import=optional:consul: instead.
    To disable this check, set spring.cloud.consul.config.enabled=false or 
    spring.cloud.consul.config.import-check.enabled=false.


I'm using org.springframework.cloud:spring-cloud-starter-consul-config:3.0.3 and spring boot 2.4.7

Thank you in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source