12 BENEFITS of Spring MVC over Struts

1. Spring provides a very clean division between controllers, JavaBean models, and views.

2. Spring’s MVC is very flexible. Unlike Struts, which forces your Action and Form objects into concrete inheritance (thus taking away your single shot at concrete inheritance in Java), Spring MVC is entirely based on interfaces. Furthermore, just about every part of the Spring MVC framework is configurable via plugging in your own interface. Of course we also provide convenience classes as an implementation option.

3. Spring, like WebWork, provides interceptors as well as controllers, making it easy to factor out behavior common to the handling of many requests.

4. Spring MVC is truly view-agnostic. You don’t get pushed to use JSP if you don’t want to; you can use Velocity, XLST or other view technologies. If you want to use a custom view mechanism - for example, your own templating language - you can easily implement the Spring View interface to integrate it.

5. Spring Controllers are configured via IoC like any other objects. This makes them easy to test, and beautifully integrated with other objects managed by Spring.

6. Spring MVC web tiers are typically easier to test than Struts web tiers, due to the avoidance of forced concrete inheritance and explicit dependence of controllers on the dispatcher servlet.

7. The web tier becomes a thin layer on top of a business object layer. This encourages good practice. Struts and other dedicated web frameworks leave you on your own in implementing your business objects; Spring provides an integrated framework for all tiers of your application.

8. No ActionForms. Bind directly to domain objects

9. More testable code (validation has no dependency on Servlet API)

10. Struts imposes dependencies on your Controllers (they must extend a Struts class), Spring doesn’t force you to do this although there are convenience Controller implementations that you can choose to extend.

11. Spring has a well defined interface to business layer

12. Spring offers better integration with view technologies other than JSP (Velocity / XSLT / FreeMarker / XL etc.)

Reference: Here

30 Responses to “12 BENEFITS of Spring MVC over Struts”


  1. 1 martin December 5, 2006 at 10:34 am

    Hi

    At first a would like to tell You that I like You article about “12 BENEFITS of Spring MVC over Struts” very much. It is helping me in my homework a lot (I am a student
    who writes a little project about framework ). But I have a few questions coresponding to this article.

    What did You mean when You said: “Spring provides a very clean division between controllers, JavaBean models, and views.” Why do You think so? And could You give the
    example of this, please? (* I know what the MVC is)

    You also said that “Spring Controllers are configured via IoC like any other objects. This makes them easy to test, and beautifully integrated with other objects
    managed by Spring.”. How it is done in Struts?

    And the last think “11. Spring has a well defined interface to business layer”. Where do You see the problem in Struts (example).

    I also have a quastion if You could tell what “bad” or “good” things do You see in JSF coresponding to Spring and Strus?

    Thanx
    Martin

  2. 2 Lijin December 7, 2006 at 1:08 pm

    Sorry for the delay martin.. :) For the last two days i was really busy …..

    I haven’t tried out JSF yet. But I can surely give some directions to make a judgment between struts and spring MVC. Unlike Struts, Spring uses IoC to inject the dependencies to the code. Spring also promote best practices of interface implementation separation and its assembly via spring context files. Thus Spring provides a pluggable configuration and a very clear separation between controllers, JavaBean models, and views. In struts the dependencies are hard coded as in any java program introducing coupling in various part of the program.

    Another major difference is that Spring is an application framework unlike the struts which is just an MVC that operated at the presentation tier. Spring provides support for all the tiers of the application including the presentation tier, business tier and the data access tier. Spring manages its business objects in a non-intrusive way (ie. it does not have any dependencies with the domain layer). It again resolves its dependencies via dependency injection and IoC.

    Best of luck for ur project :)

  3. 3 martin December 29, 2006 at 3:09 pm

    Hi Lijin

    It’s me again :). Right now I would like to give You another question (of course if I can ).

    The question is this point:
    “4. Spring MVC is truly view-agnostic. You don’t get pushed to use JSP if you don’t want to; you can use Velocity, XLST or other view technologies. If you want to use a custom view mechanism - for example, your own templating language - you can easily implement the Spring View interface to integrate it.”

    I know how easy is to use another then JSP view in Spring, because I did it :), but could You tell me how this situtation looks in Struts? I can’t find any information about this. Which of views can I integrate with Struts and is this very complicated?

    Thankx

  4. 4 Lijin January 1, 2007 at 9:13 am

    Hi martin
    You r always welcome.. :)
    My contact Id is lijinjoseji@gmail.com. Will see u der
    Lijin

  5. 5 Mohan April 10, 2007 at 7:16 am

    Hi Lijin,

    i have to create application which should support minimum 2 lakhs online user at a given time.The application is similiar to dating application.

    for this i am going to use Tomcat server bec this is free one(client too need this).

    Now my problem is whether i can go with
    Spring with Hibernate
    (or)
    Struts with Hibernate

    is it Hibernate support this much of user?

    Thanks in advance

  6. 6 Lijin April 10, 2007 at 7:46 am

    Yea sure frnd. I will recommend you the first option. Spring is an application framework and it handles Hibernate very effectively. Spring makes hibernate codes very very simple.

    But In struts I think there is no supporting classes for hibernate because it is not an application framework. I am not an expert in this Struts… but I highly going for the Spring- Hibernate option.

  7. 7 chriswk April 26, 2007 at 12:02 pm

    Also if you want to support user access you could look at Acegi Security, which would give you log-in based authentication for very little work. Take a look at http://www.acegisecurity.org. Acegi is an extension to spring and integrates very well with it. :)

  8. 8 chriswk April 26, 2007 at 12:03 pm

    Oh and btw Lijin, excellent summary.

  9. 9 Lijin April 26, 2007 at 12:13 pm

    Thanks Chris

  10. 10 Mohan May 24, 2007 at 12:29 pm

    Hi Lijin,

    I face one problem while hosting my application.

    the following may be the problem.

    If we place these two (xml-apis.jar, XercesImpl.jar) jar files in tomcat folder (X:\my_app\Portal\tomcat\common\endorsed), it will give the problem (Provider org.apache.xalan.processor.TransformerFactoryImpl not found).

    If we remove these two jar files system may work fine(Tested in local system only).

    Now i am unable to remove file in server,
    There is any other alternate way to do that one.

    Thanks in advance,
    Mohan

  11. 11 ScreenedTwenty May 31, 2007 at 4:08 am

    Cheers.

    Got an article that describes some of the time saving techniques with Spring MVC.

    http://coderslog.com/Convention_over_Configuration_for_Spring_MVC

    The site itself is a free non-profit resource for java developers working on large-scale projects.

  12. 12 vasu July 6, 2007 at 11:44 am

    hi
    i am searching for a good book for spring framw work…….can u give any prepfences….

    thanks in advance

    vasu

  13. 13 Lijin July 6, 2007 at 11:47 am

    Sure Vasu,
    “Spring in Action” from Manning will be a great one for you.

    Lijin

  14. 14 vasu July 6, 2007 at 11:57 am

    hi Lijin,
    thanks for reply..now i am working on ” Spring MVC”. Can u give any sample programs or material to understand.Again thanks for reply.

    Thanks in Advance.

    vasu

  15. 15 satya prakash July 12, 2007 at 11:30 am

    This will give good clarity on MVC with SPRING.

  16. 16 satya prakash July 12, 2007 at 11:33 am

    What does it mean by Spring Controllers?

  17. 17 Lijin September 10, 2007 at 7:41 am

    Hi Satya,

    The Controller in Spring a component that receives HttpServletRequest and HttpServletResponse instances just like a HttpServlet but is able to participate in an MVC workflow. Controllers are comparable to the notion of a Struts Action. Hope you get :)

    Lijin

  18. 18 wanlapat September 17, 2007 at 12:07 pm

    I just ask this question to my friend :D

    Thanks!!!

  19. 19 Lijin September 17, 2007 at 12:21 pm

    Actually this comparison is between struts 1.x and Spring MVC. When Struts2.0 comes into view we have to consider some more good features. It gives an excellent integration with Spring. :) We can create action beans in Spring and give to struts too.

    Lijin

  20. 20 Joserra October 3, 2007 at 6:50 am

    Lijin, I agree. I think that with Struts 2.0 this comparison is not true. Do you know any comparison beetwen Struts2 nd some other MVC frameworks?

  21. 21 Jacqui October 9, 2007 at 9:08 am

    Just a quick point about no. 5 in the list (the ability to use IoC with Spring but not with Struts) - it is possible to dependancy inject Struts Actions using the ContextLoaderPlugin and either the DelegatingRequestProcessor or DelegatingActionProxy classes (see http://www.springframework.org/docs/reference/webintegration.html).

    Other than this, great list!!

  22. 22 Lijin October 15, 2007 at 8:56 am

    @ Jossera
    Please go thru this article to get more about Struts2 :)
    Click here

  23. 23 ashish January 16, 2008 at 3:01 pm

    I am still not able to fine good article/blog comparing Struts2 and Spring MVC.

    I am planning to use Spring + Hibernate, but I am still struggling to decide for web layer.

    If I use Spring MVC, then technology stack would be simpler but I am not sure spring MVC is good enough to replace struts2?

  24. 24 SamaraRegion February 29, 2008 at 7:08 pm

    its the best post from you, thanks a lot

  25. 25 dwight March 2, 2008 at 3:33 am

    btw, the original 7 entries are close to an exact copy of this posting: http://www.mahadiscounts.com/comparison_wp.html.

  26. 26 Lijin March 3, 2008 at 5:25 am

    And dWight, who posted first?

  27. 27 Ashok kumar April 4, 2008 at 7:36 am

    hi,

    i want to know which one is better whether Spring MVC or Struts 2.0 MVC which one is best for Presentation layer

    Ashok

  28. 28 Ramapriya April 22, 2008 at 4:23 am

    Hi,

    I need simple web based application(MVC Spring Application) just show me the flow of configarations file (in spring-servlet.xml) and web.xml…….

    regards RamaPriya

  29. 29 henry fan May 9, 2008 at 5:18 pm

    I have a question that spend me couple days, how to get management bean defined in applicationContext.xml in Strut2.0 action class?

  1. 1 Spring MVC vs Struts | orientada a objetos Trackback on October 2, 2007 at 8:34 pm

Leave a Reply




View Lijin Joseji's profile on LinkedIn

Disclaimer

The information on this site is for informational purposes only. The use of any Trademark or Copyrighted material is not intended to infringe Copyright. This blog is intended to be used under a policy of personal and non commercial use.

Adds

Add to Google

Blog Stats

  • 105,953 hits

Categories