Nowadays, Enterprise System seen as a vital component in determining the success of such enterprises. Of all the other available option, J2EE is one of the most favorite solutions that many people (enterprises) choose for their driving tools to achieve such success. And yes, J2EE, through EJB, has really proven its reliability and robustness which inevitably are the vital key component needed in any Enterprise System. However, the complication, difficulties, and inflexibilities faced when developing and dealing with such EJB system, have triggered many people to start thinking to figure out another solutions, in which they can still take the advantages of EJB, but obviously with a simpler effort. That is actually when Spring Framework comes and starts to shine.
Spring Framework is an open source lightweight framework solution that offers a very high degree of flexibility and rapid turn-around (as in line with Martin Fowler’s idea of XP) in developing such a robust Enterprise System. As a matter of fact, the core concept behind the Spring Framework comes up from the idea proposed by Rod Johnson in his popular book, Expert One-on-One J2EE Design and Development (in which through this book, he also includes the 30,000 lines of code to complement his idea) released in late 2002. The huge interests and responses coming from the reader have eventually made the progress of this project goes lightning fast till finally in January 2003 they have successfully hosted their project in SourceForge.
Today, along with the many other supporting projects (like Spring Web Flow, Spring Web Services, Spring Security, Spring Batch, etc), the Apache 2.0 licensed Spring Framework has started to become such a new emerging de-facto standard in J2EE development environment adopted by many enterprises worldwide. The huge support and contribution from its community through the bugs reporting, ideas for new feature additions and enhancements; has even made the Spring evolved to be a more mature and robust framework in an incredibly high pace. Furthermore, the emergence of many Spring consulting commercial parties, like Interface21, SpringSource, Cape Henry Technologies Inc, to name a few, has obviously provided a higher level of confidence for any enterprises to adopt Spring as their underlying system.
That’s why it’s not really surprising though to see the significant growth of the number of enterprises using Spring, a free - promising open source project, with huge support from both its community and commercial parties, and still yet capable of delivering such a robust Enterprise System.
2. Spring Framework features
Spring, a robust yet lightweight framework, is in fact made up of several components which smoothly work together in supporting each other to provide such a reliable system. Here are some of the key components Spring Frameworks rely on- as noted in Professional Java Development with Spring Framework book (which is written by Rod Johnson and few other fellow Spring main developers)
- Inversion of Control (IoC)
IoC is the most famous component (and might also become the identity) of Spring Framework which could be easily recognized through the Dependency Injection usage, in which we let the framework to do more works than usual, in term of instantiating any dependencies a class may have, either through Setter injection or Constructor injection. Dependency Injection is usually applied in conjunction with one of the best programming practice concepts, i.e. programming to interface, to enable us achieving a high level of transparency of service implementation.
- Aspect Oriented Programming (AOP)
AOP is a programming concept (in complementing the OOP concept), that aims to modularize the cross-cutting concerns through aspects. SpAop, the Spring’s built in AOP, is used in many Spring’s processes like declarative transaction management, dynamic object creation, and Acegi Security . A tight integration with the other well known AOP provider like AspectJ is also provided by Spring. Furthermore, AOP is really recommended to be used when dealing with Spring Framework; however, we can still also opt not to use it anyway.
.
- MVC Web Framework
MVC Web Framework is the built in flexible Web tier component offered by Spring, that enable us to gain great advantages over strong integration with Spring’s Dependency Injection feature. However, as like AOP case, we can opt not to use Spring MVC, instead combining Spring mid-tier layer with other popular Web MVC frameworks like JSF, Struts, WebWork, and Tapestry.
- Simple and comprehensive testing strategy
Another good thing about Spring is that it facilitates us an simple yet excellent both unit testing and integration testing sets through its org.springframework.test package. The implementation of IoC which provides a high level of dependency, has eventually made testing an easy task to be done in Spring. For instance, in MVC environment, we can easily test the Controller independently of its View. Furthermore, through Spring Mock classes, we can also easily simulate the HTTP request, which usually became such a great barrier in doing the testing.
Moreover, apart from those four main features, there are still also other important modules like Data Access Abstraction, JDBC Simplification, Transaction Management, Simplification for Working with JNDI, JTA, and other J2EE APIs, Lightweight Remoting, JMS and JMX support; that really makes Spring a great framework to work with.
Provided all of those nice features offered Spring, we can see how powerful this framework is. Due to its flexible nature, as we can guess, Spring is really useful for those kind of projects which is very agile and require a rapid-turn around. Few people (including Rod Johnson) also sees that Spring will shine most when we use it in J2EE environment. Moreover, Janis Graudins, Larissa Zaitseva, through their research, found out that Spring will works best when it is used in small companies that deals with many other open source products. They later mentioned that Spring is not really preferable for projects that need a heavyweight component container.
Furthermore, on the other hand, Spring could be a boomerang as well, when we try to overuse its Dependency Injection (such as injecting every single classes, as opposed to interfaces) which will break up the concept of Interfaces and IoC itself (George Malamidis 2006). Another issue to be considered comes around from the fact that Spring Framework is developed separately from the application server, that eventually the makes it pretty hard to optimize its integration when application server is in presence.
3. Spring Framework Strength and Weaknesses
Today, Spring Framework has been used in many enterprises worldwide. Here are some of the many advantages we could get from Spring Framework.
- The non-invasive nature of Spring where the application code is made to be as independent as possible to any specified framework; has really made Spring stands-out in the crowds.
- Spring never try to reinvent the wheel, instead it even offer strong integration with other already well known proven solutions such as Hibernate (ORM framework) and AspectJ (AOP framework).
- Spring facilitates the implementation of OOP and other good programming practice like code-reusability; put up configuration value externally and independently; and programming to interfaces as opposed to classes.
- Spring architecture favors on using more POJO objects - managed in such lightweight IoC container; that could reduce the complexity of testing task a lot.
- Spring enables us to mix the architectural framework choice which makes it really flexible.
- Spring also promotes plug-ability through the concept of services, which stands independently between one another and communicates via Interface.
- Spring offers consistent approach both in different runtime environments and different part of the frameworks.
(adapted from Professional Java Development with the Spring Framework book)
- Spring enables us to easily cope with fertile changes and rapid turnaround which is the key of today enterprise system.
- The huge level of involvement from many different levels of parties (from a junior programmer to experienced professional) in Spring evolution, has made Spring a very mature product which encompass the best practice in many areas.
As like 2-sided coins, apart from its strength, Spring in fact also have several weaknesses as below.
- Unlike EJB, Spring maintains lack of compliance to standards.
- Spring is notoriously known with its over extensive XML configuration
- Too many magical things done by the framework might lead to some confusion, especially for the new learner who has no background at all.
- The learning curve needed to understand the whole thing is quite long.
4. The other options available
Since the beginning, the emergence of Spring Framework is triggered by the complexities and difficulties developer facing when dealing with EJB. Spring is aimed to provide such framework that could achieve what EJB could achieve (or even more), but with more simplified way. Thus here we’ll try to draw out some comparison between these two - as we got from the Comparative Analysis of EJB3 and Spring Framework article (written by Janis Graudins & Larissa Zaitseva) and few other resources.
| | EJB | Spring Framework |
| Transaction Support | Has its own JTA. Supports transaction attributes, but no nested transaction. | Doesn’t have its own distributed transaction component, but it support both JTA and other ORM providers like Hibernate, JDBC, etc. Supports transaction attributes, isolation level, and nested transaction (provided transaction manager supports it) |
| Persistence | Has a pretty slow Entity Beans that provides CMP and BMP strategy; can use annotation in ORM, EJB QL, and native SQL support; supports Hibernate. | Supports 3rd party ORM implementation like Hibernate, JDO, iBatis |
| AOP (Interceptor) | Have default interceptor and callback interceptor – could be implemented in same/separate class. Support annotation and deployment descriptor. | Supports declarative enterprise services, integration with 3rd party AOP provider |
| Application Configuration | Primarily through metadata annotations, but could be overridden through deployment descriptor. | Extensive use of XML configuration file. Support also Jakarta Commons Attributes and standard J2SE annotation. |
| Security Mechanism | Declarative security through both metadata annotation and deployment descriptor. | Strong integration with ACEGI Open Source Security – supports declarative security – based on IoC and AOP. |
| Service Flexibility | Highly depend on the implementation of EJB | Supports any services being set up through XML configuration |
| Service Integration | Strong integration, support clustering and performance optimization. | Not really good if we use application server since Spring developed separately from application server. |
| Add-on Functionality | Highly depend on the implementation of EJB | Highly compatible with many Open Source Project like Spring MVC, JSF |
| Testability | Hard to test; most components can be tested outside the container, except the container service. | Excellence unit testing, supports the use of mock object during testing |
| Technology Maturity | Very compliance with high standards developed by Oracle, IBM, and BEA | Quite mature – but lack of compliance to standards |
| Cost | Incur fee (however we can still use free JBoss EJB implementation) | Free since it’s an open source project |
| Documentation | Very well documented | Need more technical details and sample application. |
| Distributed Computing | Supports remote proxying call through RMI-IIOP. | Supports remote proxying call through RMI, JAX RPC, etc. |
Furthermore, as a matter of fact, apart from EJB and Spring, there are still many other available frameworks out there. Few powerful lightweight container frameworks like HiveMind and Pico are also worth to have a look and put up in our consideration. Recently many people also begin to try another open source lightweight framework running on Java 5 platform, called Google Guice, which some even refer it to be the next generation of Spring Framework. However, considering the vast scope area covered by Spring, supported by its simplicity, flexibility, community support, and all of its other benefits, it is very hard to disagree that Spring is still really the best provider in this area at the moment.
5. Conclusion
The presence of Spring Framework has really introduces a new breath in J2EE development world in which it provides another simpler alternative to EJB implementation that’s been a long time known for its reliability and complexity.
Generally speaking, Spring provides us with such huge advantages over its flexibility and reliability through its IoC, AoP, abstractions, and many other modules. The great level of involvement of its community and supports from many commercial parties has even made Spring such a promising framework for the future.
However, the rule of thumb is that there is no 1 size fits all solution. Remember that there is also a case when Spring is not really preferable to be used such as when heavyweight container is needed in the framework. Thus, along with the emergences of many other lightweight frameworks, it is very necessary to pick up the most suitable package that best cover our needs.
REFERENCES
George Malamidis, 2006, nutrun » Blog Archive » Spring IoC: The Java Enterprise drug, viewed: 19 April 2009, http://nutrun.com/weblog/spring-ioc-the-java-enterprise-drug/
Johnson R – Hoeller J – Arendsen A – Risberg T – Sampaleanu C, Professional Java Development with the SpringFramework. 2005. Indianapolis: Wiley Publishing, Inc.
Graudins J – Zaitseva L. Comparative Analysis of EJB3 and Spring Framework. 2006. International Conference on Computer Systems and Technologies – CompSysTech.
NetBeans.org, 2009, Introduction to the Spring Framework - NetBeans IDE 6.1/6.5 Tutorial, viewed: 10 April 2009, http://www.netbeans.org/kb/61/web/quickstart-webapps-spring.html
Risberg T – Evans R - Tung P, 2009, NetBeans Wiki: SpringMVConNetBeansGlassFish, viewed: 11 April 2009, http://wiki.netbeans.org/SpringMVConNetBeansGlassFish
BIBLIOGRAPHIES
Rod Johnson, 2005, Enterprise Java Community: Introduction to the Spring Framework, viewed: 18 April 2009, http://www.theserverside.com/tt/articles/article.tss?l=SpringFramework
SpringSource, 2009, SpringSource.org:, viewed: 18 April 2009, http://www.springsource.org/about
Nestor Urquiza, 2008, Thinking In Software: Should I learn Spring Framework?, viewed: 18 April 2009, http://thinkinginsoftware.blogspot.com/2008/09/should-i-learn-spring-framework.html
A Tate B – Gehtland J, Spring – A Developer’s Notebook. 2005. O’Reilly Media, Inc.
SpringFramework.org, 2007, Spring - Java/J2EE Application Framework, viewed: 13 April 2009, http://static.springframework.org/spring/docs/1.2.x/reference/index.html
SpringFramework.org, 2007, Spring - Java/J2EE Application Framework, viewed: 14 April 2009, http://static.springframework.org/spring/docs/1.2.x/reference/index.html
Benoy Jose, 2009, Java(TM) Boutique - The Spring Framework, viewed: 13 April 2009,
http://javaboutique.internet.com/tutorials/spring_frame/
Wikipedia, 2009, Spring Framework - Wikipedia, the free encyclopedia, viewed: 12 April 2009,
http://en.wikipedia.org/wiki/Spring_framework
Jerome Jaglale, 2009, Spring MVC Fast Tutorial: Form Processing, viewed: 13 April 2009,
http://maestric.com/en/doc/java/spring/form_processing
Zabada Technology, 2009, Spring MVC Basics : Zabada Technology, viewed: 13 April 2009,
http://www.zabada.com/tutorials/spring-mvc-basics.php
Steve Anglin, 2007, ONJava.com -- The Next Spring: Google Guice?, viewed: 19 April 2009, http://www.oreillynet.com/onjava/blog/2007/03/the_next_spring_google_guice.html
Floyd Marinescu, 2006, InfoQ: Spring and EJB 3 Compared, viewed: 19 April 2009, http://www.infoq.com/news/spring-ejb-3-compared
William Louth, 2009, Benchmark Analysis: Guice vs Spring, viewed: 20 April 2009, http://www.javalobby.org/articles/guice-vs-spring/?source=archives
Ryan de Laplante, 2008, ryandelaplante.com : End of Spring vs EJB wars in sight?, viewed: 20 April 2009, http://www.ryandelaplante.com/rdelaplante/entry/end_of_spring_vs_ejb
Google, 2008, google-guice - Google Code, viewed: 20 April 2009, http://code.google.com/p/google-guice/
