Environment variables for list in spring boot configuration
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
Spring Boot can bind environment variables to list properties, but the exact naming convention matters. In practice, the two most useful approaches are a single comma-separated variable or a set of indexed variables, both of which participate in Spring Boot’s relaxed binding system.
Bind a Comma-Separated Variable to a List
Suppose your application has a configuration property named app.allowed-hosts. With @ConfigurationProperties, Spring Boot can bind that property directly to a List<String>:
Then set one environment variable:
Spring Boot splits the value and binds it as a list. This is often the simplest solution for short string lists.
Use Indexed Variables When You Need More Control
If you prefer one variable per element, you can use indexed binding:
This style is helpful when deployment tooling manages each variable separately. The important mapping rule is that app.allowed-hosts becomes APP_ALLOWED_HOSTS.
Prefer @ConfigurationProperties Over Manual Splitting
Once the values are bound, you can inject and use them normally:
This is cleaner than reading one raw string with @Value and splitting it manually across the codebase.
Use SPRING_APPLICATION_JSON for Complex Structures
If the list becomes more complex, such as a list of nested objects, JSON can be easier to manage:
That approach is especially useful in container environments where passing structured configuration as one variable is convenient.
Validate the Bound List Early
If the list is required, validate it at configuration-binding time instead of discovering bad values later during request handling:
That lets the application fail fast when the environment variables are missing or malformed.
It also keeps configuration mistakes close to startup logs, which is much easier to debug than discovering them only after the first request path executes.
For operational settings such as allowed hosts, broker addresses, or bootstrap servers, that early validation is usually the difference between a quick deployment fix and a confusing runtime outage.
Common Pitfalls
The most common mistake is using the wrong environment variable name. Dots and hyphens from property names do not survive directly; Spring Boot expects uppercase names with underscores.
Another issue is assuming that every deployment platform passes commas and quotes exactly the same way. If values contain spaces or special characters, test how the shell or orchestrator actually passes them to the JVM.
People also mix indexed and comma-separated styles for the same property without understanding precedence, which can produce confusing overrides.
Finally, avoid scattering manual parsing logic across services when Spring Boot can bind the list for you once at startup.
Summary
- Spring Boot can bind lists from environment variables using comma-separated or indexed syntax.
- Translate property names such as
app.allowed-hostsintoAPP_ALLOWED_HOSTS. - Prefer
@ConfigurationPropertiesfor list binding instead of manual string splitting. - Use
SPRING_APPLICATION_JSONwhen the structure is more complex than a plain list of strings. - Verify naming and quoting behavior in the real deployment environment.
Related reading
- Eppstein's algorithm and Yen's algorithm for k shortest paths
- equals vs Arrays.equals in Java
- Equivalence classes and union/find in a functional language
- Errata in the original paper on suffix arrays?
- Error1, 0 Plugin with id ''com.android.application'' not found
- Error - is not marked as serializable
- Error AccessControlListNotSupported when trying to create a bucket ACL in AWS
- Error dictionary update sequence element 0 has length 1; 2 is required on Django 1.4

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.