In Spring (Boot) I can externalize annotation values to application / environment properties using the ${...}
syntax:
@RequestMapping("${some.path.property}")
I can also map a controller to more than one path:
@RequestMapping("/one", "/two")
How do I combine the two? I would like to define a list of paths in my properties, either as comma-separated /one, /two
or (preferably) as a list in my application.yaml
:
some.path.property:
- /one
- /two
But how can I interpolate either kind of list into the annotation?
@RequestMapping(???)
Edit: I couldn't figure out how to read the entire list from YAML (maybe because it's turned into separate properties some.path.property[0]
, some.path.property[1]
... at YAML parse time?)
For the simpler case of a single CSV property, say:
some.csv.property: /one, /two
I can use a property substitution: "${some.csv.property}"
or an explicit SpEL split: "#{'${some.csv.property}'.split('[, ]+')}"
to convert it into an array, but in both cases it only work for @Value
annotations. If I try it on @RequestMapping
, I always end up with a single path.
Edit2: I can do this, where --
is just a random string that is not a valid path, but it's super ugly:
@RequestMapping(
"${some.path.property[0]:--}",
"${some.path.property[1]:--}",
"${some.path.property[2]:--}",
"${some.path.property[3]:--}",
"${some.path.property[4]:--}",
"${some.path.property[5]:--}",
"${some.path.property[6]:--}",
"${some.path.property[7]:--}",
"${some.path.property[8]:--}",
"${some.path.property[9]:--}"
)