-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
Nathan Smith opened SPR-6206 and commented
When implementing an generic interface method in a controller, spring mistakenly thinks that the compiler-created bridge method is an annotated request method, causing the following error (from attached test case:)
java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path '/method': {public org.springframework.web.servlet.ModelAndViewAnnotationMethodHandlerAdapterTest$TestControllerImpl.method(AnnotationMethodHandlerAdapterTest$TestEntity), public org.springframework.web.servlet.ModelAndView AnnotationMethodHandlerAdapterTest$TestControllerImpl.method(java.lang.Object)}. If you intend to handle the same path in multiple methods, then factor them out into a dedicated handler class with that path mapped at the type level!
The issue is that with something like the following:
public interface TestController<T> {
public ModelAndView method(T object);
}
@Controller
public interface TestControllerImpl<MyEntity> {
@RequestMapping("/method")
public ModelAndView method(MyEntity object) {
return new ModelAndView();
}
}
the compiler built bridge method is detected as being annotated, causing the ambiguity. The bug appears to have been committed here:
When isHandlerMethod was changed to use findAnnotation (which will look through bridge methods and return true if the bridged method is annotated) from isAnnotationPresent on the method itself (which will show the bridged method as not annotated)
I've attached a patch to restore the previous behaviour, as unannotated methods should never show us as matches.
Affects: 3.0 RC1
Attachments:
- AnnotationMethodHandlerError.zip (2.64 MB)
- SPR6206.patch (761 bytes)
Issue Links:
- Broken @RequestMapping inheritance [SPR-6502] #11168 Broken
@RequestMapping
inheritance
Referenced from: commits 17d5b31