• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What Are the Advantages of Using the Spring Over the Struts + Other Frameworks?

 
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are the advantages of using the Spring rather than the Struts in combination of other free source frameworks?
 
author
Posts: 422
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There was a previous discussion of SpringMVC vs. Struts in this forum.
 
author
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Adding on to what Craig said, Struts has one more thing going for it that may be considered an advantage - it has been around for quite some time and is easily the most wide spread open source Java web framework. There are tons of resources on Struts - articles, books, etc. There are also a lot more jobs out there for developers with Struts experience than with Spring MVC experience.

All that said, I prefer Spring MVC to Struts by a wide margin. I have never been of fan of Struts (as Craig can attest) and I find Spring MVC to be a much cleaner framework. I also expect as Spring gets more and more mindshare (as well as other web frameworks such as WebWork, Tapestry and JSF), Struts's popularity will diminish.
 
Craig Walls
author
Posts: 422
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ryan Breidenbach:
Adding on to what Craig said, Struts has one more thing going for it that may be considered an advantage - it has been around for quite some time and is easily the most wide spread open source Java web framework.



Ryan makes a good point here. Struts has a huge mindshare...virtually everyone knows a little something about how it works and there are tons of books on it.

Originally posted by Ryan Breidenbach:

All that said, I prefer Spring MVC to Struts by a wide margin. I have never been of fan of Struts (as Craig can attest) and I find Spring MVC to be a much cleaner framework. I also expect as Spring gets more and more mindshare (as well as other web frameworks such as WebWork, Tapestry and JSF), Struts's popularity will diminish.



Struts was a good idea at the time. But it's starting to show its age. Spring MVC is based on the same Model 2 approach as Struts, but without the annoyances of ActionForm.

To further explain my gripes about ActionForm, imagine a typical Struts application where Employee is a model object. In the presentation layer, perhaps you have an EmployeeForm object which is a subclass of ActionForm. In the service layer you have an Employee value object which is a simple POJO. Now (if for no other reason than to exaggerate the problem), suppose that you use Entity EJB in the persistence layer. Thus you have an EmployeeBean EJB.

See the problem? You have 3 objects which represent the same thing. And you have to write code to translate the concept of an employee from the presentation layer through to the persistence layer and back again.

Now suppose that your app is based on Spring MVC and Hibernate. The same Employee POJO can be used in all three layers. One POJO is better than a trinity of ActionForm, POJO, and EJB any day.
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello authors,

Do you suggest moving existing struts application to Spring framework?
 
Ryan Breidenbach
author
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pradeep Bhat:
Hello authors,

Do you suggest moving existing struts application to Spring framework?



I have done this before of a relatively small application and it is a lot of effort. I wouldn't recommend it unless you have a very compelling reason to do this - "I think Spring is cooler than Struts" is not compelling enough ;-)
 
If you like strawberry rhubarb pie, try blueberry rhubarb (bluebarb) pie. And try this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic