从属性文件获取带有@RequestMapping值的控制器链接

时间:2016-05-03 10:09:19

标签: java spring

下面有一个控制器,api.prefix是从属性文件中设置的。

import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*;
...

@RequestMapping("/${api.prefix}/test")
public class ApiRestController {
    ...
    @RequestMapping(value = "/one", method = RequestMethod.POST)
    HttpEntity<?> collect(@RequestBody ApiRequestBody input) {
        ...
        linkTo(methodOn(this.getClass()).data(input.id)).withSelfRel();
        ...
    }

    @RequestMapping(value = "/{id}/details", method = RequestMethod.GET)
    ResponseEntity<?> data(@PathVariable String instrumentId) {
        ...
    }
}

假设在属性文件上设置了api.prefix=/v234。问题是,当我向/v234/test/one请求时,methodOn(Class)引发java.lang.IllegalArgumentException消息Map has no value for \'api.prefix\';

但如果我设置@RequestMapping("/v234/test"),它就可以正常工作。

0 个答案:

没有答案