Hello! I trying to get property from application.yml.

My application.yml is:

resource:
 apiUrl: ${RESOURCE_API_URL}v2/
 api-url: ${RESOURCE_API_URL}v2/

I am trying to get this properties via @Value

@Value("${resource.apiUrl}")
private String resource1;

@Value("${resource.api-url}")
private String resource2;

For example If I Set environment variable RESOURCE_API_URL as http://example.com/api/ when I get next properties:

resource1 = http://example.com/api/v2/ (ok) resource2 = http://example.com/api/ (without prefix)

I don't know, it maybe a bug or not. I want to follow naming conventions and have properties in kebab-case instead of camelCase, but get same behaviours. Thank you!

Spring boot version: 2.2.5.RELEASE. Also in 2.2.1.RELEASE

Comment From: vladigeras

I guess, that environment variables parser compares RESOURCE_API_URL as resource.api-url and replaces it fully. If yes, I think, its unexpected. Probably parser should work between borders of value ${RESOURCE_API_URL} only instead of fully resource.api-url

Comment From: wilkinsona

As noted in the documentation, @Value does not support relaxed binding. We have https://github.com/spring-projects/spring-boot/issues/20507 tracking some improvements to the documentation in this area.

Comment From: wilkinsona

You are also defining properties in your YAML that will clash with those in the environment due to the similarity of RESOURCE_API_URL and resource.api-url once they have been translated into the canonical form. I would encourage you not rely upon subtly different properties when trying to add the v2 suffix in your yaml.

Comment From: vladigeras

Thank you for explaining