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
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
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
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
Hi martin
You r always welcome..
My contact Id is lijinjoseji@gmail.com. Will see u der
Lijin
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
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.
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.
Oh and btw Lijin, excellent summary.
Thanks Chris
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
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.
hi
i am searching for a good book for spring framw work…….can u give any prepfences….
thanks in advance
vasu
Sure Vasu,
“Spring in Action” from Manning will be a great one for you.
Lijin
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
This will give good clarity on MVC with SPRING.
What does it mean by Spring Controllers?
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
I just ask this question to my friend
Thanks!!!
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
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?
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!!
@ Jossera
Please go thru this article to get more about Struts2
Click here
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?
its the best post from you, thanks a lot
btw, the original 7 entries are close to an exact copy of this posting: http://www.mahadiscounts.com/comparison_wp.html.
And dWight, who posted first?
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
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
I have a question that spend me couple days, how to get management bean defined in applicationContext.xml in Strut2.0 action class?