'How to mock Consul properties in local environment of SpringBoot app?

There is a SpringBoot applicattion with the following configuration:

application.yml

custom:

  api-base-url: http://${application.environment}-internal-api:8080

  secret-key: ${my.consul.property.secretKey}

Normally on staging env, the placeholders are being resolved by a configuration in Consul (all needed spring cloud consul dependencies were added).


I would like to run application locally and override both of these properties (api-base-url, secret-key) with the following properties file:

/my/local/directory/app-local.yml

application.environment: local

custom:

  api-base-url: http://extenal-api.org

  secret-key: 36vch34c53j54v563ch3

Trying to run spring-boot:run command I get a property resolving error.

mvn spring-boot:run -D spring-boot.run.arguments=--spring.config.additional-location=/my/local/directory/app-local.yml


java.lang.IllegalArgumentException: 
   Could not resolve placeholder 'my.consul.property.secretKey' 
   in value "${my.consul.property.secretKey}"
    at o.s.u.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:180)
    at o.s.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126)
    at o.s.c.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:239)

And even if we exclude custom.secret-key, it appears that custom.api-base-url is resolved to http://local-internal-api:8080, that means the app-local.yml is processed, application.environment is resolved to "local", but the other two properties are still resolved from the original values in application.yml

What is the proper way to override properties and placeholders for running application locally?



Sources

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

Source: Stack Overflow

Solution Source