Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 opened this issue Oct 14, 2016 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Oct 14, 2016

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:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Oct 14, 2016

Juergen Hoeller commented

This looks like a duplicate of #15682 which we intend to tackle for 5.0.

@spring-projects-issues
Copy link
Collaborator Author

Alexandre Navarro commented

Thanks, sorry for duplication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants