Why I must use @RequestParam
annotation on implementation class instead of interface class only? I'm using interface and implementation in separate files approach. It seems that usage of @RequestParam
on interface has no effect.
public interface GreetingService {
@RequestMapping(value = "/greeting", method = RequestMethod.GET)
public Greeting greetingByGet(@RequestParam(value="name", defaultValue="World") String name);
}
@RestController
public class GreetingController implements GreetingService {
@Override
public Greeting greetingByGet(
/**
* Why do I need to duplicate @RequestParam annotation on
* implementation to make it work ???
* Otherwise GET default value is not used.
*/
@RequestParam(value="name", defaultValue="World")
String name) {
...
}
}
It make sense for annotations like @Transactional
which are implementation specific but are @RequestParam
, @RequestBody
, etc. implementation specific? Or this is a part of interface contract? @RequestBody(required)
suggest it is a part of contract so using it on interface should be supported.
There is an explanation here: Spring MVC Annotated Controller Interface but the question is: Is there more general idea behind this explanation? Or only Spring internals force us to do it like it is now?
It is hard to understand why annotations are not inherited to implementation.