Issue Details (XML | Word | Printable)

Key: APF-984
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Matt Raible
Reporter: Alex Coles
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
AppFuse

Upgrade Spring MVC Controllers to use annotations

Created: 17/Dec/07 03:37 PM   Updated: 09/May/10 10:49 PM   Resolved: 09/May/10 10:49 PM
Component/s: Web - Spring
Affects Version/s: None
Fix Version/s: 2.1.0-M2

File Attachments: 1. Java Source File BaseController.java (6 kB)
2. Java Source File UserController.java (4 kB)



 Description  « Hide
Upgrade Spring MVC Controller classes to use annotations:
http://blog.interface21.com/main/2007/11/14/annotated-web-mvc-controllers-in-spring-25/

Form Controllers which extend BaseFormController (and in turn, Spring's SimpleFormController) can make use of the @RequestMapping annotation to define their request mappings:
 org.appfuse.web.controller.FileUploadController
 org.appfuse.web.controller.SignUpController
 org.appfuse.web.controller.UserFormController

Other controllers should be rewritten to be annotation-based controllers, with the @Controller annotation:
 org.appfuse.webapp.controller.PasswordHintController
 org.appfuse.webapp.controller.UserController

Tutorials should also be updated.

Sort Order: Ascending order - Click to sort in descending order
Matt Raible added a comment - 17/Dec/07 03:41 PM
While I like the annotation-based features added to Spring MVC, I'm not convinced they're better than extending classes (SimpleFormController and implementing Controller). Also, does putting URLs in Java code make sense? I think it's best to discuss this on the user list and see what people think.

Marcello Teodori added a comment - 31/Jul/08 04:11 AM
Wouldn't it make sense to use a mixed approach to get the benefit of annotations while keeping URL mappings in a single location, like the one proposed here:
http://blog.springsource.com/main/2008/03/23/using-a-hybrid-annotations-xml-approach-for-request-mapping-in-spring-mvc/
?

Donny A. Wijaya added a comment - 10/Oct/08 08:49 AM
A controller that has similar BaseFormController functionalities. This controller is for Spring 2.5 annotated MVC.

Donny A. Wijaya added a comment - 10/Oct/08 08:51 AM
An example of class extending BaseController.

Donny A. Wijaya added a comment - 10/Oct/08 08:55 AM
Sorry this looks like Spam. You can delete all my comments above. I thought when I comment on each file the comments would appear next to the file. Sorry about this.

Anyway I created a BaseController for Spring Annotated MVC. I also provided an example class using this BaseController. Sorry for not providing the other classes. But the other classes are DTOs and nothing much. I hope these two classes could be helpful.

Regards

Donny

Marc Schipperheyn added a comment - 05/Jan/09 07:04 AM
Personally, I haven't looked back since upgrading my controllers. 100 times more convenient. A real pleasure versus the headaches of xml configuration. Also, the Spring team have stated that they will deprecate the controller hierarchy in the 3.0 release in favour of annotations and will eliminate it all together shortly after.