Struts is an MVC-framework, while Spring is a full-stack application framework that provides an MVC Framework (Spring MVC) as one of its many modules. In fact, it is possible to integrate a Struts-based web tier with Spring-managed components in the middle-tier. At the core Spring provides an Inversion of Control container to remove the burden of dependency management from application code. Spring also leverages Aspect-Oriented Programming to decorate POJOs with enterprise behavior - such as transactions, security, and logging. In addition to its MVC web framework, Spring provides support libraries for data access, messaging, scheduling, etc.
As far as comparing the two web frameworks (Struts and Spring MVC), they are similar enough that developers familiar with Struts should be able to pick up Spring MVC rather quickly. For example, Spring MVC Controllers play the same general role as Struts' Actions - handling requests and typically delegating to the application layer.
I'm not sure if you are referring to Struts 1.x or Struts 2, but if you are considering frameworks for new development projects, it is definitely important to recognize that Struts 2 (current BETA is 2.0.5) is a vastly different framework (originally known as WebWork2) with many improvements and therefore worth learning. As long as you are learning a new framework, it is probably worth having a look at Spring MVC as well. Regardless of what you choose for MVC, you can still leverage Spring for the application layer (Struts-2 also integrates with Spring).
Assuming that you are comparing Spring MVC with Struts 1.x, there are some signficant differences. Spring is interface based while Struts requires concrete inheritance (e.g. extend the Action class). Virtually every collaborator within the Spring MVC framework is defined as an interface thereby offering significant flexibility and extensibility (Strategy Pattern). Many convenience classes are provided as potential strategies. For example, there is a SimpleFormController that handles the entire form lifecycle (display form, bind/validate, if errors display/else handle submission). The base classes are typically examples of the Template pattern - exposing extension points while also enforcing a well-defined algorithm. Spring MVC is designed for loose-coupling between the Controller and View. Whereas Struts 1 was designed for forwarding to JSP views, Spring offers flexible view integration - including Velocity, FreeMarker, PDF, Excel, XML/XSLT, as well as forwarding to JSPs. Another way Spring MVC promotes loose-coupling is by working with simple Objects in the model (as opposed to ActionForms). The interface-based design and emphasis on loose-coupling promote testable code. For example, it is possible to test Validators in isolation (in fact, Spring Validators are not tied to the web-tier at all, so they can be reused in other layers - e.g Web Services). The Controllers can even be tested prior to implementing any Views. Spring MVC also provides HandlerInterceptors so that you can reuse logic that needs to be applied before/after invoking multiple Controllers.
As far as comparing the two web frameworks (Struts and Spring MVC), they are similar enough that developers familiar with Struts should be able to pick up Spring MVC rather quickly. For example, Spring MVC Controllers play the same general role as Struts' Actions - handling requests and typically delegating to the application layer.
I'm not sure if you are referring to Struts 1.x or Struts 2, but if you are considering frameworks for new development projects, it is definitely important to recognize that Struts 2 (current BETA is 2.0.5) is a vastly different framework (originally known as WebWork2) with many improvements and therefore worth learning. As long as you are learning a new framework, it is probably worth having a look at Spring MVC as well. Regardless of what you choose for MVC, you can still leverage Spring for the application layer (Struts-2 also integrates with Spring).
Assuming that you are comparing Spring MVC with Struts 1.x, there are some signficant differences. Spring is interface based while Struts requires concrete inheritance (e.g. extend the Action class). Virtually every collaborator within the Spring MVC framework is defined as an interface thereby offering significant flexibility and extensibility (Strategy Pattern). Many convenience classes are provided as potential strategies. For example, there is a SimpleFormController that handles the entire form lifecycle (display form, bind/validate, if errors display/else handle submission). The base classes are typically examples of the Template pattern - exposing extension points while also enforcing a well-defined algorithm. Spring MVC is designed for loose-coupling between the Controller and View. Whereas Struts 1 was designed for forwarding to JSP views, Spring offers flexible view integration - including Velocity, FreeMarker, PDF, Excel, XML/XSLT, as well as forwarding to JSPs. Another way Spring MVC promotes loose-coupling is by working with simple Objects in the model (as opposed to ActionForms). The interface-based design and emphasis on loose-coupling promote testable code. For example, it is possible to test Validators in isolation (in fact, Spring Validators are not tied to the web-tier at all, so they can be reused in other layers - e.g Web Services). The Controllers can even be tested prior to implementing any Views. Spring MVC also provides HandlerInterceptors so that you can reuse logic that needs to be applied before/after invoking multiple Controllers.
Comments