aspose file tools*
The moose likes Other Application Frameworks and the fly likes What Are the Advantages of Using the Spring Over the Struts + Other Frameworks? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "What Are the Advantages of Using the Spring Over the Struts + Other Frameworks?" Watch "What Are the Advantages of Using the Spring Over the Struts + Other Frameworks?" New topic
Author

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

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
What are the advantages of using the Spring rather than the Struts in combination of other free source frameworks?
Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 301
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.


Spring in Action - Unleash POJO power in your applications!
Modular Java - Discover the secret weapon to modularity on the Java platform!
XDoclet in Action - Your complete guide to code generation with XDoclet.
Ken Krebs
Ranch Hand

Joined: Nov 27, 2002
Posts: 451
There was a previous discussion of SpringMVC vs. Struts in this forum.


kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
Ryan Breidenbach
author
Greenhorn

Joined: Jan 06, 2004
Posts: 18
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
Ranch Hand

Joined: Sep 19, 2003
Posts: 301
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.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Hello authors,

Do you suggest moving existing struts application to Spring framework?


Groovy
Ryan Breidenbach
author
Greenhorn

Joined: Jan 06, 2004
Posts: 18
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 ;-)
 
wood burning stoves
 
subject: What Are the Advantages of Using the Spring Over the Struts + Other Frameworks?