Thursday, January 20, 2011

Spring vs Struts

Some differences between Spring and Struts Framework:

· Struts is a web framework only, Struts can be compare with the SpringMVC. And SpringMVC is a subset of Spring framework. So we can say that Struts can be seen as the subset of the spring framework in functionality point of view.

· What Action class does in struts, Controller does in Spring. And Action in Struts is an Abstract Class but Controller in Spring is an Interface, This is very good advantage of the spring.

· Spring dont have any Action Form, it bind the http form values directly into POJOs. Instead of initializing the Form Bean spring directly initialize the domain object.

· ActionForward in struts is replaced with the ModelAndView in Spring. Model component contain the business object to be displayed via view component.

· Unlike Struts Spring dont provide any separate tag library.

· Spring has excellent support classes for jdbc.

· Classes like MappingSqlQuery, SqlUpdate, StoredProcedure help you manage the selects, inserts and stored procedures.

· With Spring you need not even have try, catch and finally in your jdbc code.

· Spring handles opening, transaction management and closing of connections.

· When it comes to designing your application I would say that integrating struts with Spring gives you quite a few options. Struts for the View and Control, Spring for the jdbc part.

· Struts implement MVC Design Patten where as Spring implements IOC Design Pattern and addresses AOP Cross cutting concerns.

· Struts is heavy weight where as Spring is light weight framework.

· Struts is tightly coupled, Spring is loosely coupled.

· Struts will be generally used as a Front End Frame work. Spring has Spring WebFlow for the same purpose, which is part of Spring Framework.

· The other major advantages of spring Framework is it handles

o Transaction management

o support for Messaging

o Support and Integration with Other Frame works.
(E.g.: Hibernate, Struts, Tapestry.. etc)

· Struts Framework have some advantages

o Excellent support for Tag Library, which has wide industry acceptance.

o Easy to integrate with other client side technologies.

BENEFITS of Spring MVC over Struts

Spring is a powerful Java application framework, used in a wide range of Java applications. It provides enterprise services to Plain Old Java Objects (POJOs). Spring uses dependency injection to achieve simplification and increase testability.

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.)

BENEFITS

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

· 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.

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

· 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.

· 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.

· 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.

· 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.