Why Spring

安浩瀚
2023-12-01

For a lot of reasons (heavy session use, horrible track record wrt backwards), Spring supports an MVC framework - which Java EE doesn't. If you want to do a web application using pure Java EE.

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.

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. and spring haslibraries for making your life easier when you deal with JDBC, ORM, JMS, LDAP, remoting, and other Java EE technologies. 


And I found Umesh Awasthi  talk about Spring 3 VS Strusts 2:

Well Both Struts2 and Spring3 are very much similar in many respects.Both are action oriented framework and much same in the flow.Spring MVC came out due to all known limitations of Struts1. but when you come to choose Struts2 vs Spring3 MVC there is not much you can differentiate and both are well designed and good framework. for Struts2 as its webwork based framework but with lots of improvements over webwork.one major advantage is UI tags support for Struts2 regarding spring3 mvc its equally good and powerfull positive side is its well and very deep integration with Spring framework.

We are using Struts2 with Spring DI and transcation management in our few projects and in some using Spring MVC. it only matters you choice and your brand inclination. 

In my opinion its not a good practice to compare like designed framework,better come up with your requirements what exactly are the requirements of your project than do a analysis which framework provides best and very similar requirements as per your needs rather than doing a plain comparasion

In my opinion, I like strusts 2. 1st they're similar, 2nd I like the idea of the struts structure, just for me, easier to control and design for big projects. Spring is more like plus this, using that. I just feel that I got lost sometime.


STRUTS 2 VS SPRINGMVC – BATTLE OF THE FRAMEWORKS  by Justin Freeman 

source:[http://blogs.isostech.com/web-application-development/struts-2-vs-spring-mvc-battle-frameworks/]
Over the years in my work as a consultant, I’ve worked with several companies that were looking to convert their legacy systems to a web-based solution. Once they selected Java (great choice!) as their language, their next question is usually, “What Java framework should we use?”

In my experience, it usually comes down to Struts 2 or SpringMVC. I have worked extensively with both of these frameworks, so I will compare and contrast them for you. Keep in mind that there really isn’t a definitive “correct” framework to choose. You should look at your options, the dynamics of your development team and what you are trying to accomplish before you choose a framework. I’m hoping that this will help guide you in your decision making.

SPRINGMVC

Spring is basically a Java framework that allows you to create complex web applications through simple components and configurations. There are other aspects of Spring that you can use independently of SpringMVC, such as dependency injection and aspect-oriented programming. For the purposes of this article, we don’t need to talk about those because they can be used with SpringMVC or Struts 2. In my experience, they work really well with either.

SpringMVC is part of the Spring framework that is used for handing and processing web-based requests. It follows the basic MVC (Model-View-Controller) pattern. Spring-created JavaBeans are the model. The controller is the DispatcherServlet, which handles all requests and passes them to the corresponding controller. A nice feature is that you can use annotations to handle this requirement instead of using the infamous application-context.xml file. Anyone who used Spring in the early days knows that this file can get large quickly. Breaking this context file into smaller files just makes it more complicated. Anyway, the last piece is the view, which is usually composed of JSPs. However, if you are developing webservices the view could be a number of things. We will come back to webservices later, but this is your basic layout of Spring and its components.


STRUTS 2

Struts 2 is also a Java request-based framework that allows you to create web applications. The Struts 2 framework follows the basic MVC pattern. The controller is called the ActionController. It is backed by mappings in a struts.xml file that allows requests to be forwarded to the appropriate action. In my experience, most people use EJBs or even Spring JavaBeans as their model. However, the view is important here because Struts 2 has its own view language. This is an advantage over SpringMVC in that you can just learn Struts 2 and you can build a Java framework from beginning to end, which helps with your development team’s learning curve. I have found that companies looking to ramp up quickly will go the Struts 2 route because it is easier to get up and running.


Now that we have a basic understanding of the frameworks, let’s compare and contrast the frameworks using a few of the web components and possible issues you would come across while learning and developing using these frameworks.


AJAX SUPPORT

Ajax has become a good technology for displaying dynamic content or field validation for web-based applications. In my work as a consultant, I have been fortunate to work with Ajax in both SpringMVC and Struts 2 environments. Struts 2 has built-in Ajax support so there is no need to import a third-party library. So if you are keeping score, Struts 2 has its own view language, controller and Ajax support. Again, once your learn Struts 2 you can pretty much develop a web application from beginning to end without the assistance of almost any other framework.

Although SpringMVC does not have native Ajax support, this just gives a more seasoned developer the ability to choose its Ajax library. This is especially important since your development team may already have knowledge or a preference for an Ajax library, allowing you to leverage that knowledge. For example, in one company that was switching to a SpringMVC environment, many of the developers were familiar with the Dojo Ajax library. So instead of switching to Struts 2 and learning a new Ajax library, they were able to use all the knowledge of Dojo and make the full learning curve of switching to SpringMVC a little easier. I would give the edge to Struts 2 here because it’s easier to hit the ground running, provided that your developers do not have any experience with Ajax libraries.


RESTFUL WEBSERVICES SUPPORT

In any request-based web application, it is becoming increasing popular to use RESTful webservices because they are easier to develop and maintain and startup costs are minimal. In a world where IT is seen more as a cost than an expense, this is pretty important. Most developers I have come across don’t know how RESTful webservices work; they just know how to write them. It has really become that simple.

In Struts 2, I found it a little difficult to set up RESTful webservices when I first learned it. We essentially needed 2 separate xml files (one for RESTful URLs and the re-direct and the second for the struts action mapping). Another hassle is that in your Java Action you don’t necessarily know that this is a RESTful webservice or if it is just a plain old Struts Action. This can be confusing to some less experienced developers.

In SpringMVC, RESTful webservices take advantage of annotations which not only makes webservices easier to identify, it also makes them easier to develop and maintain. The majority of your changes all happen in the Java class and you just have to touch one xml file once as opposed to Struts 2 where you need to edit 3 different places for adding or removing webservice. I really like the RESTful webservice support in SpringMVC with an assist from annotations because everything is one place and therefore development time is shorter.


CONTINUING MAINTENANCE AND EVOLVING FRAMEWORK

Java in general is constantly evolving and its frameworks are no different. They are both open source so improvements and efficiencies are always on the horizon. I find that Struts 2 is a more mature technology in that the changes to the basic framework have been minimal. SpringMVC, and along with it Spring, is constantly changing and getting better. The issue is that your developers will have to constantly keep up with the technology in order to improve the application as Java grows, web browsers change and other improvements happen around the webspace. It only sounds daunting because most IT firms do not take this into account. They only care about fixing bugs and enhancing the application. Eventually, old technologies will die off and new technologies and techniques that make web applications perform more efficiently will replace them. In this regard, SpringMVC applications must be constantly monitored for improvements and upgrades are a must. This is less important for Struts 2 because the underlying framework is not changing much. So, something else to think about when choosing between SpringMVC and Struts 2 is the maintenance costs and how much your department can afford.

IN CONCLUSION

These are just some of the things you can use when deciding between SpringMVC and Struts 2. Like I said in the beginning, there isn’t really a definitive answer to which one is better. However, in my opinion, I would say if you are looking for a stable framework you should choose Struts 2. If you are looking for a more robust framework, you should choose SpringMVC.

 类似资料:

相关阅读

相关文章

相关问答