Skip to content

Spring Mvc Annotations in argument of a method (like @Path) annotated with @RequestMapping are not supported when you create a @RestController via an Interface [SPR-14805] #19371

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions