Originally posted by JiaPei Jen:
What are the advantages of using the Spring rather than the Struts in combination of other free source frameworks?
Compared to Struts, Spring MVC has both advantages and disadvantages...
First, a level-set for those who don't know: Spring MVC controllers are roughly the equivalent of Struts actions. (Spring MVC's BaseCommandController is the closest approximation of a Struts Action.) Also, where Struts have ActionForms, Spring has "commands". And, instead of ActionForward, Spring has ModelAndView.
Advantage: Spring has a rich selection of Controller implementations ranging from the simplest (the Controller interface) to the very powerful (AbstractWizardFormController) and everything in between. You get to choose the controller implementation that best suits your needs. In Struts, you only have the Action class...if you need anything simpler, you are out of luck...if you need something more powerful, you have to subclass Action and implement it yourself.
Advantage: Spring's Controllers are much easier to
test than Struts Actions. Spring's commands are anything that extends java.lang.Object (thus easy to mock). Struts form beans are classes that extend ActionForm (a bit harder to mock).
Disadvantage: The only disadvantage of Spring MVC over Struts is that because Spring MVC has a very rich selection of controllers, it may be harder to understand and know which controller to use. In fact, for a Spring newbie, the list of controller options can be overwhelming. But, if you take a look at Figure 8.4 in "Spring in Action", you'll see that Spring's Controller interface is much simpler than Struts' Action and that the other implementations progressively build upon that.