Spring is an open-source framework created by Rod Johnson and it addresses the major complexities involved in developing enterprise application , especially when EJB is involved. At this junction to say simple benefit of Spring is that it is POJO (Plain Old Java Objects) based.
Spring is lightweight inversion of control and Aspect Oriented framework.
Inversion of Control
When IoC is applied, objects get their dependencies from the Spring container rather than the objects looking themselves for the dependencies. Reverse JNDI to say in simple terms.
Inversion of Control is a loose term. It is interchangeably used with dependency injection. Dependency injection aptly says what IoC is all about.
Aspect Oriented
Business logic are mostly in verticals. An enterprise would have core businesses align as verticals with dependencies among each other. OOP is a perfect paradigm for such business problems where reusability , maintenance , scalability are key. In each business function, we could find certain repetitive functionalities which are not 100% related to that business function. Rather they appear scattered across all business modules. Typically they are horizontal functions or simply cross-cutting concerns. OOP is best for vertical functions.
AOP solves the problem by giving aspects such as logging, transaction management, authentication to the business methods. Thereby the code is cleaner, easily testable and maintainable.
A cliche example of aspect : Logging. If you have already known this example, excuse me for not giving a different example. But to make someone understand what AOP, logging is the best feature to explain. Loggers typically appear at will. Typically at the start and end of the method. Why dirt the code with logger statement when it has cleanly done what it is expected to do. Logging is an aspect and you can ask Spring to do the task of giving the advice and when to give the advice.
Spring framework is made of many modules. It is not necessary to use all the modules to be able to completely work with spring. Thats what makes Spring unique. Struts is good but there is a tight coupling when it comes to integration with other frameworks. Spring allows easy integration for other frameworks. If you want to either TopLink, iBatis, Hibernate as your ORM quite easily with Spring. Ok.! Lets see what are the Spring modules
All modules are built on top of the container which is the heart of Spring. A container is J2EE context is that provides the low-level services which are essentially the building blocks of enterprise application.
- Spring Container : Fundamental of Spring. Spring's BeanFactory is the heart of Spring based application. BeanFactory provides the IoC.
- Application Context module : Extends the container module to provide internalization support, EJB integration, life cycle management. (Not very clear. Superficial now)
- Spring AOP module : As discussed earlier, this makes Spring an AO framework. Spring AOP API confirms with the AOP Alliance API specification and hence can support interoperability of AOP implementations
- JDBC abstraction and DAO module : Imagine flyweight pattern. You can bury complex database calls, connection establihsment under a set of classes and expose them to your business calls. Declarative transaction management possible through this module which inturn depends on AOP module. Meaningful exceptions are available and thus you needn't decipher the SQL Error code to track what the exception is and why it occured.
- ORM integration module : Integrates well with any ORM framework. It provides hooks to major ORM frameworks like Hibernate, JDO, iBatis
- Spring Web Module : Allows easy intergration with other MVC frameworks like Struts. It is built on top of application context module and very much into request-response management, programmatic binding of request parameters to business objects
- Spring MVC framework : Spring also gives a separate MVC framework eventhough it supports good integration with Struts. Importantly this uses IoC to segreggate neatly the role of controller from business objects. Multiple view possible using Spring MVC

No comments:
Post a Comment