0

Suppose I have @RestController and I want to put the @RequestMapping path into properties file.

Properties Config

mock.api.path=mock/v1/demo,mock/v2/demo,mock/v3/demo

Code.

    @Value("#{'${mock.api.path}'.split(',')}")
    private String[] name;  //debug this, it is array [mock/v1/demo,mock/v2/demo,mock/v3/demo]

    @Value("${mock.api.path}")
    private String[] name2; //debug this, it same to name, [mock/v1/demo,mock/v2/demo,mock/v3/demo]

    //@RequestMapping(path = "${mock.api.path}")  // with this, the path is "mock/v1/demo,mock/v2/demo,mock/v3/demo" , String is not splitted.

    @RequestMapping(path = "#{'${mock.api.path}'.split(',')}") // with this, it still not working.
    public String getData(HttpServletRequest request) throws IOException {

        return "done";
    }

My Question

  1. How could I get this (Array in config) working
  2. why @RequestMapping(path = "${mock.api.path}") not split the string (not worked as @Value name2)

Thanks in Advance

user3644708
  • 2,466
  • 2
  • 16
  • 32

0 Answers0