Quick revision
The short answer
To set spring.datasource.hikari.maximum-pool-size from the environment, we replace dots with underscores, remove the dashes and use upper case: SPRING_DATASOURCE_HIKARI_MAXIMUMPOOLSIZE. For the second element of the list my.servers, we put the index between underscores: MY_SERVERS_1_. Spring Boot's relaxed binding maps these names back to the canonical kebab-case property names, and in @Value we should use that canonical form so the matching works.
What to remember
In this answer, we saw that Spring Boot maps environment variables to properties by lower-casing them and treating underscores as dots, so we write SPRING_DATASOURCE_HIKARI_MAXIMUMPOOLSIZE by replacing dots with underscores, removing dashes and using upper case. List elements use the index between underscores, MY_SERVERS_1_ for the second element, and overriding a list replaces it as a whole. Relaxed binding maps these names to the canonical kebab-case names, and @Value matches them only when it uses the canonical form.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
To set spring.datasource.hikari.maximum-pool-size from the environment, we replace dots with underscores, remove the dashes and use upper case: SPRING_DATASOURCE_HIKARI_MAXIMUMPOOLSIZE. For the second element of the list my.servers, we put the index between underscores: MY_SERVERS_1_. Spring Boot's relaxed binding maps these names back to the canonical kebab-case property names, and in @Value we should use that canonical form so the matching works.
Why this question is asked
In containers, environment variables are the most common way to configure a Spring Boot service, but most environments only allow letters, digits and underscores in variable names, so dots, dashes and brackets cannot be written directly. Getting the translation wrong is a silent failure: the variable is set, nothing complains, and the service runs with its default. Interviewers ask this to see whether we know the exact rules rather than guessing. In this answer, we will recap relaxed binding, derive the variable for the pool size step by step, see the common mistake, handle list elements, and look at how @Value fits in.
1A Quick Recap of Relaxed Binding
Every Spring Boot property has a canonical name: lower case, with dots between the parts and dashes inside a part, such as spring.datasource.hikari.maximum-pool-size. Relaxed binding means Spring Boot accepts other spellings of the same name from different sources: maximumPoolSize in a properties file, maximum_pool_size in YAML, and an upper case form with underscores from the environment, and binds all of them to the same field.
Environment variables get special treatment because of their restricted character set. Spring Boot reads a variable name by lower-casing it and treating each underscore as a dot. There is no way to write a dash, so dashes are simply left out, and the binder matches the result against the canonical name ignoring the dashes.
2Deriving the Variable Step by Step
We start from the canonical name and apply three rules in order: replace dots with underscores, remove dashes, convert to upper case.
| Source | Spelling | Binds? |
|---|---|---|
application.yml | spring.datasource.hikari.maximum-pool-size | yes (canonical) |
application.properties | spring.datasource.hikari.maximumPoolSize | yes |
| Environment variable | SPRING_DATASOURCE_HIKARI_MAXIMUMPOOLSIZE | yes |
| Environment variable | SPRING_DATASOURCE_HIKARI_MAXIMUM_POOL_SIZE | no: means maximum.pool.size |
Notice why the dashes are removed rather than turned into underscores. Each underscore means a dot, so an underscore in place of a dash would split the name at a point where the canonical name has no dot.
3The Common Mistake
The most frequent error is SPRING_DATASOURCE_HIKARI_MAXIMUM_POOL_SIZE, which looks natural. Spring Boot reads it as spring.datasource.hikari.maximum.pool.size, a nested name with three extra levels. No property has that name, so nothing binds, and nothing fails either: Hikari keeps its default of 10 connections, and the service runs out of connections under load.
So after setting a variable, it is worth confirming that it took effect, for example with the Actuator endpoint /actuator/env/spring.datasource.hikari.maximum-pool-size, which shows the variable as the winning source when the name is right and shows nothing from the environment when it is wrong.
4Setting List Elements
A list property such as my.servers is written in YAML as a sequence, and in a properties file with indexes in brackets, my.servers[0] and my.servers[1]. Brackets are not allowed in environment variable names, so Spring Boot uses the index surrounded by underscores instead: MY_SERVERS_1_ is my.servers[1]. Indexes start at zero, so the second element has index 1.
There is a catch with lists: when a list is defined in more than one source, Spring Boot does not merge the elements, it takes the whole list from the source with the highest precedence. So if we only set MY_SERVERS_1_ in the environment, we do not patch one element of the YAML list; we replace the list with one that has only an element at index 1, which can fail binding or lose element 0, depending on the version. The safe practice is to set every element from the environment, or use the comma-separated form.
5Relaxed Matching and @Value
@ConfigurationProperties binding understands all these forms. @Value does too, but only if the placeholder uses the canonical kebab-case name. Spring Boot then looks the name up in a way that matches the environment variable form; with a camel case placeholder the match is not guaranteed.
6Follow-up questions
What about a map key, such as my.weights.eu-west?
Map keys from environment variables are awkward because the key's own dashes and dots cannot be expressed: MY_WEIGHTS_EUWEST becomes the key euwest. For maps with special keys, a config file or SPRING_APPLICATION_JSON is the better source.
Does case matter in the variable name?
Upper case is the convention and the documented form. Spring Boot lower-cases the name when mapping it, but environment variables are case-sensitive on Linux, so two variables that differ only in case can both exist and confuse things. Sticking to upper case avoids that.
Why not use SPRING_APPLICATION_JSON for everything?
It is useful for structured values and special keys, but a whole block of JSON in one variable is hard to review and easy to break with a missing quote. For simple values, plain variables are clearer.
7Conclusion
In this answer, we saw that Spring Boot maps environment variables to properties by lower-casing them and treating underscores as dots, so we write SPRING_DATASOURCE_HIKARI_MAXIMUMPOOLSIZE by replacing dots with underscores, removing dashes and using upper case. List elements use the index between underscores, MY_SERVERS_1_ for the second element, and overriding a list replaces it as a whole. Relaxed binding maps these names to the canonical kebab-case names, and @Value matches them only when it uses the canonical form.
Open with
For the pool size, I take the canonical name, spring.datasource.hikari.maximum-pool-size, replace the dots with underscores, remove the dashes and upper-case it, which gives SPRING_DATASOURCE_HIKARI_MAXIMUMPOOLSIZE. The dashes are removed, not turned into underscores, because Spring Boot reads every underscore as a dot.
Then, if they want more
So MAXIMUM_POOL_SIZE would mean maximum.pool.size, which binds to nothing, and Hikari would silently keep its default of ten. For a list element, brackets are not allowed in variable names, so the index goes between underscores. The second element of my.servers is index one, so the variable is MY_SERVERS_1_.
I should keep in mind that a list from a higher-precedence source replaces the whole list. So I would set all the elements, MY_SERVERS_0_ and MY_SERVERS_1_, or use the comma-separated MY_SERVERS form, rather than trying to patch one element. All this works through relaxed binding, which maps environment names to the canonical kebab-case property names. @ConfigurationProperties gets it fully.
With @Value, I write the placeholder in the canonical kebab-case form so the environment variable can match. To confirm a variable took effect, I check the Actuator env endpoint for the property, which shows the environment variable as the winning source.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Boot reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How do you set the property spring.datasource.hikari.maximum-pool-size from an...": https://scrivio-interview-library.netlify.app/spring-boot/externalized-configuration/dccad0ddeb/