Skip to main content

Repost about Spring and Struts

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.

Comments

Popular posts from this blog

Замена салонного воздушного фильтра в Аккорд Купе 6-го поколения

Начнем с того, что салонные фильтры в седане и купе различаются и в купе их два. К сожалению об этом я узнал после того как разобрал панель :). Собвственно и сам процесс замены: Снимаем бардачек. Снимаем заглушки и выкручиваем два шурупа за ними

Полетка в Прагу

Захотелось отдыха. Захотелось ажно в феврале. Захотелось как всегда спонтанно. И так, две недели на организацию... Надо шевелиться. И так - куда ехать? На слуху трендовое направление - Египет. Шуршание по сайтам туристических конторок - нипанятна. Решили ориентироваться по гатэлям. Тут могу посоветовать хороший русскоязычны ресурс tophotels.ru . Удобно, качественно и понятно. Денег как сигда жалко. Смотрим на ****. Грусть - тоска. На денюжки которые за них хотят хоцца поехать в крым на все лето... Сутки сомнений - и направление Ебипет исключено из вариантов.

Плагин FreeMarker для Netbeans

В свободное время набадяжил плагинчик для NetBeans (любимая IDE). Плагинчик умеет совсем чуть-чуть, но этого мне очень не хватало :). Встречайте freemarkerfornetbeans . Подсветка кода и подсказки FreeMarker синтаксиса. Если кому-нить понадобиться, будем допиливать.