Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for environment variables with square brackets #5315

Closed
jrglee opened this issue Mar 2, 2016 · 3 comments
Closed

Support for environment variables with square brackets #5315

jrglee opened this issue Mar 2, 2016 · 3 comments
Labels
theme: config-data Issues related to the configuration theme type: enhancement A general enhancement
Milestone

Comments

@jrglee
Copy link

jrglee commented Mar 2, 2016

The ability to define keys in an array format like service.server[0]=http://server1 is is great when used in conjunction with @ConfigurationProperties.

Unfortunately the square brackets are considered special characters for environment variable names.

  • When using Docker, I can use the -e flag to define SERVICE_SERVER[0]=http://server1 and it works
  • When using Bash's export like export SERVICE_SERVER[0]=http://server1 I get a not a valid identifier error
  • In Kubernetes I can only set environment variables in the C_IDENTIFIER format with is the regexp [A-Za-z_][A-Za-z0-9_]*. There is a related discussion about dashes vs underscores Cannot use dash in environment variable names in a pod definition kubernetes/kubernetes#16863

I chatted with @philwebb yesterday about this issue. While I can find other ways to pass those values to the application, i.e.: use an environment variable to define application args and let the entrypoint in Docker take care of it; it would be great if Spring could handle that out-of-the-box. One idea I discussed with Phil is to use double _ around the index like SERVICE_SERVER__0__.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 2, 2016
@philwebb philwebb removed the status: waiting-for-triage An issue we've not yet triaged label Apr 25, 2016
@philwebb
Copy link
Member

I think this is something we should consider around 2.0 when we try to rationalize relaxed binding.

@mbhave
Copy link
Contributor

mbhave commented Apr 28, 2017

The new binder supports this by allowing environment variables to be specified using _ for indexes. For eg: HOST_0 is equivalent to host[0].

@mbhave mbhave closed this as completed Apr 28, 2017
@mikeloll
Copy link

mikeloll commented Jan 3, 2018

For anyone interested, here are the release notes for the new data binding:

https://github.com/spring-projects/spring-boot/wiki/Relaxed-Binding-2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: config-data Issues related to the configuration theme type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

6 participants