Reputation: 1995
I have a interface for spring-mvc 3.1 controllers that looks like
public interface RestCRUDOperations<T> {
@RequestMapping(value = "/{id:\\d+}",
method = RequestMethod.GET,
produces = "application/json")
public ResponseEntity<T> getById(@PathVariable("id") String sourcId);
//other code omitted
}
What i observed was, in implementating classes the @RequestMapping annotation was still having effect (without me having to copy that over the method implementation) but the @PathVariable weren't having effect , until i copy paste the annotation at corresponding place before the parameter. Does anybody know if there is a way around this ? And/or spring acknowledges this as a bug it intends to fix or something ??
EDIT :-
One ugly way could be to have an abstract class translating methods i.e public abstract class RESTAdapter implements RestCRUDOperations
that provides final implementation to these methods and delegates to 2 abstract methods and this abstract class is what the controllers extend.
I wanted something automatic.
Upvotes: 1
Views: 964
Reputation: 11
There is an issue on the tracker now .. see https://jira.spring.io/browse/SPR-14526
Upvotes: 1
Reputation: 68
All annotations that I have seen pretty much work the same. The reason is, the code that scans for them only examines the lowest level child in the hierarchy.
As a workaround, I recommend writing a protected wrapper method in a base class. You can then use it from either the base class, which implements this interface, or the derived class. This is similar to your suggestion.
Lastly, as a bit of friendly advice, it is probably a bad idea to be extending other Controller classes from a purely structural point of view. You will almost always regret it.
Upvotes: 0