Skip to content

HandlerMethodResolver does not handle hierarchy of generic interfaces with @MVC annotations [SPR-7355] #11985

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

Closed
spring-projects-issues opened this issue Jul 6, 2010 · 6 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jul 6, 2010

Richard Larson opened SPR-7355 and commented

Given the following type of construct 2 problems arise:

  1. the bridged methods do not get matched and thus we get "HTTP Status 405 - Request method 'POST' not supported", for the update method.

2)The @ModelAttribute ("note") annotation on the loadModel method is not picked up from the interface.

We are using standard Spring WebMVC annotation driven setup (<mvc:annotation-driven /> and <aop:config proxy-target-class="true">) with Hibernate JPA models.

This may be related to a previous issue:
http://jira.springframework.org/browse/SPR-5191?page=com.atlassian.jirafisheyeplugin%3Acrucible-issuepanel

public interface ModelController<Model> {
	@ModelAttribute("note")
	public Model loadModel(@RequestParam(required = false) Long id);

	@InitBinder
	public void initBinder(WebDataBinder binder);
}
public interface EditableController<Model> extends ModelController<Model> {

	@RequestMapping (method = RequestMethod.POST )
	public String update(@Valid @ModelAttribute("note") Model command,
			BindingResult result);

	@RequestMapping(method = RequestMethod.GET)
	public void edit(@RequestParam Long id);
}
@Controller
public class PersonController implements EditableController<Person> {
	public void edit(Long id) {...}

	public String update(Person command, BindingResult result) {...}

	public void initBinder(WebDataBinder binder) {...}

	public Person loadModel(Long id) {...}

}

Affects: 3.0.2, 3.0.3

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

Richard Larson commented

Created a spring forum post: http://forum.springsource.org/showthread.php?p=308123#post308123

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

This seems to be a problem with a hierarchy of generic interfaces, actually: It works for me if a controller implements a generic interface directly but breaks if that interface is part of a generically typed interface hierarchy...

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

This should be fixed in Spring 3.0.4, as part of a general overhaul with respect to handler method resolution. Will be available in tonight's 3.0.4 snapshot - feel free to give it an early try...

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Praveen J commented

The fixes in 3.0.4 still do not solve this problem.

The handler methods are getting added properly to the handlerMethods list.
But the modelAttributeMethods and initBinderMethods are not updated appropriately.

Is there a reason why AnnotationUtils.findAnnotation(method, RequestMapping.class) is used to identify a handler method, but AnnotationUtils.findAnnotation is not used for ModelAttributes or InitBinder. Rather, method.isAnnotationPresent is used to find the annotation.

If method.isAnnotationPresent is replaced with AnnotationUtils.findAnnotation for initbinder and modelAttribute, it would solve the problem.

@spring-projects-issues
Copy link
Collaborator Author

Praveen J commented

I am referring to the code in the method "public void init(final Class<?> handlerType)"
of org.springframework.web.bind.annotation.support.HandlerMethodResolver

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Our processing of handler methods, init binder methods and model attribute methods is consistent now. This will be available in tonight's 3.0.5 snapshot - please give it an early try and let us know whether it works for you...

Juergen

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) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants