Issue
I’m making a config in my Spring application and I want to define a map:
@Value("${ordering:#{{:}}")
private Map<String, List<String>> ordering;
Here’s what’s in my config:
ordering = {'SOMEVALUE' : {'ONE', 'THREE', 'TWO'}, 'OTHERVALUE' : {'THREE', 'ONE', 'TWO'}}
But this always gets read as null (so I assume invalid SpEL).
The name of the variable and config value aren’t misspelled and other values are loaded from the same config, so those parts are set up properly.
How should such a map be defined, what am I screwing up? Is there an online tool for parsing SpEL?
I tried several things: adding and removing the single ticks, same for double ticks and wrapping the lists in an extra {}, but none of these helped and the value is still set to null.
I also tried modifying the annotation, to no avail:
@Value("#{${ordering:#{{:}}}")
Solution
I think I figured out what I was doing wrong: My actual SpEL might have been correct at some point, but I’m parsing the data read from that and storing it in another variable, at which point ordering
was null
. What I forgot to consider is that the other field I’m parsing ordering
into might (and does) get evaluated first.
Answered By – András Ballai
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0