Description
Alexandre Navarro opened SPR-14805 and commented
Spring Mvc Annotations in argument of a method (like @Path
) annotated with @RequestMapping
are not supported when you create a @RestController
implementation via an Interface annotated
Example to illustrate the problem :
Interface
@RequestMapping(value = UserResource.API_URL , produces = {V2_JSON_VALUE})
@FeignClient("user")
public interface UserResource {
String API_URL = "/api/users";
@RequestMapping(value = "/{id:.+}" , method = RequestMethod.GET)
@ResponseBody
User getUser(@PathVariable("id") String userId);
}
Implementation
@RestController("userRestControllerV2")
public class UserRestController implements UserResource {
public static final String API_URL = "/api/users";
public User getUser(String userId) {
return new User(userId);
}
}
You have to change the implementation to
public User getUser(@PathVariable("id") String userId) {
return new User(userId);
}
to have a work around. The different annotation (like @RequestMapping
) on class / method are well recognized.
I really want to use all the annotations in the interface in order to use the same interface between the server (implemented via @RestController
) and the client (implemented feign via spring-cloud). Very useful when you develop many microservices via spring-boot and spring-cloud (eureka).
Don't hesitate to comment if it is not clear.
Affects: 4.3.3
Issue Links:
- Enable REST controller method parameter annotations on an interface [SPR-11055] #15682 Enable REST controller method parameter annotations on an interface ("duplicates")