Monday, December 12, 2011

What is Spring and why came into Picture ?

In order to start with Spring, it's very important to clear concepts about what is Spring and why it came into picture. Once you have idea about Spring picture, you will be sure able to easily understand 7 Spring modules described here as well. So Let's Jump into Spring :)

Java Enterprise Edition (JEE) component that was used to implement business logic was Enterprise Java Beans (EJB). However, EJBs are heavy weight components that require application servers to run. 

This was the scenario before the Spring Framework came into the picture. The Spring Framework provides a lightweight container to run the objects implementing business logic. In other words, Spring Framework-based business objects do not require an application server to run.

Spring Framework: What is it? Spring Framework is “An open-source layered Java/J2EE application framework having a light-weight container implementing Inversion-of-Control and Aspect Oriented Programming.” The key points here are “layered application framework” and “Inversion of Control and Aspect Oriented Programming.” and they are divided into two broad categories:
  1. Patterns
  2. Components of the Framework

Spring has two patterns at its core. They are:
    • Inversion-of-Control(IOC)
    • Aspect Oriented Programming(AOP)

Inversion-of-Control - refer to Spring DI and IOC concept and Example

Aspect Oriented Programming(AOP) is “An approach to programming that attempts the separation of concerns, specifically cross-cutting concerns, as an advance in modularization.” Here, the key point is separation of concerns. 

Separation of concerns means that the applications are divided into modules that do not overlap in terms of functionality.Logging is an example of such a concern.by using AOP a developer can encapsulate cross cutting concerns.


Some of useful component/modules are:
  1. MVC Component: Spring MVC - Model,View and Controller. Spring MVC renders view using data provided by Model and it does this by providing dispatcher servlet , ViewResolvers and ModelAndView. refer to Spring examples
  1. IoC Container: It's core component of the framework. IoC lets the developer implement the business logic as Plain Old Java Objects (POJO) and wire them up so that they can be injected or called at runtime.  refer to Spring DI Examples
  1. DAO Support: Using this component, spring provides functionality of  JDBC, Hibernate, and iBatis to access persisted data.

Spring Framework Modules : Spring contains a lot of functionality and features, which are well-organized in seven modules shown in the diagram below


1. The Core package is the most fundamental part of the Spring and IOC and DI functionality.

On top of the Core package , there is Context package, providing a way to access beans in a framework-style manner

2. The DAO package provides a JDBC-abstraction layer that removes long JDBC coding and parsing of database-vendor specific error codes. 

3. The ORM package provides integration layers for popular object-relational mapping APIs, including JDO, Hibernate and iBatis.

4. Spring's AOP package : AOP allows you to define method-interceptors and pointcuts to cleanly decouple code implementing functionality that should logically speaking be separated.

5. Spring's Web package provides basic web-oriented integration features, such as multipart functionality, initialization of contexts using servlet listeners and a web-oriented application context.

6. Spring's Web MVC package provides a Model-View-Controller implementation for web-applications.