Replacement for Spring's AbstractCommandController
I'm trying to learn Spring MVC from Spring In Action 2nd Edi开发者_StackOverflow社区tion (Covers Spring 2.0).
My IDE tells me that AbstractCommandController
has been deprecated. Has it been replaced? What is the recommended way of handling cases for which one would have extended AbstractCommandController
?
As of Spring 3.0, the entire Controller
hierarchy has been deprecated and replaced by the annotation-style of controllers. This makes things considerably simpler, you no longer have to worry about which of the various base classes to extend.
In fact, you won't even find mention of the old hierarchy in the Spring reference manual any more, just the new annotation-style.
Annotated controllers perform the same functionality as AbstractCommandController
by simple auto-binding of method parameters, e.g.
@Controller
public class MyController {
@RequestMapping
public String handleMe(Command command) {
...
}
}
Your book covers Spring 2.0 which relies on subclasses of the AbstractCommandController
. In Spring 2.5 the equivalent of an AbstractCommandController
is the AbstractController
. In Spring 3.0 (as others have pointed out) the equivalent is a properly annotated @Controler
class.
Like the javadoc of AbstractCommandController
says:
@deprecated as of Spring 3.0, in favor of annotated controllers
So, look at the spring reference documentation for annotated controllers.
Here is an example of annotation-based Spring MVC that might help get you started.
精彩评论