Spring Boot Version
plugins {
id 'java'
id 'org.springframework.boot' version '3.1.0'
id 'io.spring.dependency-management' version '1.1.0'
id 'org.asciidoctor.jvm.convert' version '3.3.2'
}
Problem
When I inject URI format's value to application.yml file, the value has a different String iteral value according to the key's hypen count.
What I did
I deployed a java spring application in a K8S cluster, and set a URI format's value as a pod container's environment. And I received the injected value in the application.yml file, Here is my sample codes.
// a part of k8s deployment
env:
- name: EXAMPLE_SERVICE_URL
value: "http://172.0.0.1:8080"
// Spring's Application Yaml file
outer-example-service: // case 1
url: "http://${EXAMPLE_SERVICE_URL}:8080"
outer-service: // case 2
url: "http://${EXAMPLE_SERVICE_URL}:8080"
// Spring's Value Annotation
@Slf4j
@Service
public class OuterExampleService
{
public OuterExampleService (
@Value("${outer-example-service.url}")
String exampleUrl
) {
log.info(
"exampleUrl: {}", exampleUrl
)
}
}
I tested the following two cases. (All settings that are not mentioned are the same.)
- Using two hypen at the key name of application.yml file (ex. outer-example-service)
- Using one hypen at the key name of application.yml file (ex. outer-service)
The case 1's exampleUrl is this. http://http://127.0.0.1:8080:8080
The case 2's exampleUrl is this. http://127.0.0.1:8080
The difference is only the count of hypen.
Is this an intended action of Spring's Profile Setting with Yaml file? I'm not sure this is a kind of bug or just a misusing case.
Comment From: wilkinsona
I believe this is a Spring Framework issue: https://github.com/spring-projects/spring-framework/issues/31707#issuecomment-1830260487.