google-labs‎ > ‎

Struts Vs Spring

posted Dec 5, 2014, 5:02 AM by Bipin Sasi

Submitted by Raghvendra Kumar

Spring supports a large number of standards, btw. JSR330, JMS, JSR250, JPA, JSR303, the whole servlet stack, JSF, JMX, a zillion others. Actually, if you look at it by the numbers, Spring supports more specifications than a Java EE 6 "web profile" implementation ;-) So, that argument doesn't buy you anything. You can create an entirely Java, entirely standards-oriented application in Spring. In fact, if you use Spring 3.1, you can avoid all XML - web.xml, persistence.xml, ejb-*xml, orm.xml, etc, which is not true of Java EE 6 (and especially of java EE 5 or below). The problem comes when you want to do stuff the standards don't support. Then, you'll need some extra, like Spring MVC.

Spring supports an MVC framework - which Java EE doesn't. If you want to do a web application using pure Java EE, you only have servlets and JSPs or pure JSF. If you want to be more productive, you'll end up using an extra project (one that's not "standard") like Spring MVC, GWT, Wicket, or Seam or even just straight PrimeFaces. Seam's a bad choice for a lot of reasons (heavy session use, horrible track record wrt backwards incompatibility between 1 and 2, and 2 and 3, etc. For the best reasons to avoid Seam 3, see this blog from JBoss where the Seam project lead admits Seam 3 isn't very useful for developers... also, check out the comments.)

So, that leaves you back to Struts vs. Spring MVC. And, as others have pointed out, it's an easy choice: Spring MVC's constantly updated and backwards compatible (for all the talk of "standards," the "standard" Java EE APIs buy you nothing in terms of safety of investment: a mildly sophisticated J2EE application written in 2004 won't compile or run on today's Java EE 6, where as a Spring application written in 2002 will run just fine today.)

Spring MVC has tight integration with all the other Spring libraries and Spring MVC's easy. for a good example on getting started, check out http://blog.springsource.com/2011/01/04/green-beans-getting-started-with-spring-mvc/ Spring MVC supports everything that Struts 1 (or 2) supports, and a lot more that builds on top of it for when you need more specialized support: SPring Web Flow for wizards, REST support, Spring WS for SOAP based web services, Spring BlazeDS for Flex integration, etc: all of it builds on top of Spring MVC and can be layered on top of the clean foundation it provides.



Comments