下面有一个控制器,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")
,它就可以正常工作。