Spring SpEL to set RequestMapping path with a list

Viewed 221

I want to programmatically set the paths on a rest service. I have this bean method which has all the paths.

public List<String> getSubscribeChannelsForRest() { .. }

This is the rest service

@RestController
public class RestMessageController {

    @PostMapping(
            path = { "#{somebean.getSubscribeChannelsForRest()[0]}",
                     "#{somebean.getSubscribeChannelsForRest()[1]}",
                     "#{somebean.getSubscribeChannelsForRest()[2]}"
            })
    public String processMessage(@RequestBody String messageBody, HttpServletRequest request) { .. }

The above code works but I want to avoid hard coding the array numbers. There is what I tried.

@PostMapping(
            path = { "#{somebean.getSubscribeChannelsForRest()}",

This doesn't work because the spring method RequestMappingHandlerMapping.resolveEmbeddedValuesInPatterns(String[] patterns) takes the above SpEL as a single element array. I've checked the trace logs and all the element in the given list get concatenated .

0 Answers
Related