I am using a custom code generator to transform a REST contract in to Java interfaces. Below find a sample of a generated resource Java interface.
@Generated(
date = "2018-01-30T11:56:25.156Z",
comments = "Specification filename: country.v1.json",
value = "GENERATOR"
)
@RequestMapping("/v1/countries")
public interface CountriesResource {
@RequestMapping(
method = RequestMethod.GET,
path = "/{id}",
produces = MediaType.APPLICATION_JSON_VALUE
)
@ResponseBody
LandGetResourceModel getEntity(@PathVariable("id") String id);
}
Additionally the generator creates an @RestController
implementation a that interface for Spring to create a controller bean.
@RestController
public class CountriesResourceImpl implements CountriesResource {
@Override
public CountryGetResourceModel getEntity(String id) {
return new CountryGetResourceModel();
}
}
So far everything works fine. Spring creates the RestController bean and the HTTP calls are directed correctly to the corresponding Handler method (e.g. getEntity
).
The problem is that for some reason Spring is not able to resolve path variables when they are defined on the interface. All calls containing a path variable are handled but the method parameter of any path variable is null
. If I then add the PathVariable
annotation to the implementation class Spring is able to resolve the corresponding value.
Is there a way to tell Spring to read the PathVariable
from the interface method declaration like it does for the RequestMapping
annotations?