Skip to content

Clearly document the limitations of @Value with respect to relaxed binding #4413

@johanhaleby

Description

@johanhaleby

Suppose I have a property like this:

@Value("${something.with-dash}") private String mySomething;

It's hard to make Spring map hyphens like with-dash from an environment variable. Let's say I've built my spring onejar then I can't just provide an environment variable like this (bash):

$ SOMETHING_WITH-DASH=Something java -jar my-spring-onejar.jar

You need to use a work-around like this:

$ env 'SOMETHING_WITH-DASH=Something' java -jar my-spring-onejar.jar

But in certain frameworks such as Kubernetes you cannot use a hyphen in environment variables since they use the C_IDENTIFIER format as the lowest common denominator. I've aded an issue for this in Kubernetes but I'm not sure if they're willing to change it.

So I wonder if instead Spring could enhance its way that hyphens are treated in environment variables when matching the @Value annotation? For example if SOMETHING_WITH_DASH could map to something.with-dash?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions