Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home4/vir007/public_html/ on line 2
Free Online Springs Tutorials,Springs Programming Tutorials,Springs notes
Search Site

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home4/vir007/public_html/ on line 2
J2SE [Java 2 Standard Edition]
Core Java Introduction
Exception Handling
Collection & Util Classes
Input & Output Streams
Adwance Windows Toolkit (AWT)
Swings (Adwance GUI)
Event Handling
Java Networking
Remote Method Invocation (RMI)
Java Database Connectivity (JDBC)
J2EE [Java 2 Enterprise Edition]
Java 2 Enterprise Edition Intoduction (J2EE)
Server Side Programming (Servlet)
Java Server Pages (JSP)
Enterprise Java Bean
MVC Framework (Struts)
Advance Framework (Springs)
Object-relational mapping (Hibernate)
eXtensible Markup Language (XML)
Asynchronous JavaScript and XML (AJAX)
Monthly News Letter
Free SCJP Samples
Interviews Questions For Freshers
Interviews Questions For Experinced
Most Visited Links
Most Freaky Links

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home4/vir007/public_html/ on line 2

Introduction to Springs

Just as Hibernate attacks CMP as primitive ORM technology, Spring attacks EJB, it says EJB is complicated
and not susceptible to unit-testing.

Instead of EJB, Spring suggests that we make use of ordinary Java beans, with some slight modifications, to get
all the supposed advantages of EJB environment.

Thus, Spring is borne as an alternative to EJB essentially. However, as a concession to the existing EJB
investments, Spring is designed to operate with EJB if required.

The main aim of Spring is to simplify the J2EE development and testing.

The main advantages of EJB2 are:

a) Transaction Management
b) Declarative Transaction support
c) Persistence ( CMP & BMP)
d) Declarative Security
e) Distributed Computing (Container managed RPC)

Spring does not attempt to do everything by itself but supports the best of breed technologies for each of these
1. Instead of CMP & BMP, it supports several persistence technologies like JDO, Hibernate and OJB.
These ORM tools are far more capable than the implementation in CMP.
2. Spring makes use of Acegi, an open-source Security framework and provides declarative security
through spring configuration file
3. Spring provides proxying for RMI (special remoting technologies like Burlap) JAX-RPC & webservice
while EJB provides container-managed remote method calls.
4. Spring can offer declarative transaction like EJB. But spring provides declarative rollback behavior also
,for methods and exceptions

Thereby, it gives the following advantages over EJB2.
1. Testing is easier. We do not need to start the EJB container , for testing.
2. As Spring is based on the standard JavaBeans naming convention, programmers find it.
3. It makes use of AOP(Aspect-Oriented Programming) which is a very recent and useful paradigm.
4. It is flexible.

Spring Framework

Spring`s goal is to be an entire Application Framework. Other popular frameworks like Struts, Tapestry,
JSF etc.
, are very good web tier frameworks but when we use these framework, we have to provide additional
framework to deal with enterprise tier that integrates well with these framework. Spring tries to address this
problem by providing a comprehensive framework, which includes
    1. a core bean container,
    2. an MVC framework,
    3. an AOP integration framework,
    4. a JDBC integration framework and
    5. an EJB integration framework.
    6. It also provides integration modules for O/R mapping tools like Hibernate and JDO.

Thus spring framework can be thought of as a layered architecture consisting of seven well defined modules.
The function of each component is as follows:

String Framework

1. Spring Core:
The core container provides the fundamental functionality of Spring. It`s primary component is the
`BeanFactory`, an implementation of the Factory pattern. The BeanFactory applies the IOC (Inversion of
pattern to separate an application`s configuration and dependency specification from the actual
application code.

2. Spring Context/Application Context:

The Spring context is a configuration file that provides context information to the Spring framework . The
Spring context supplies enterprise services such as JNDI access, EJB integration, e-mail, internalization,
validation, and scheduling functionality

3. Spring AOP:(Aspect-Oriented Programming)

The Spring AOP module integrates aspect-oriented programming functionality directly into the Spring
framework, through its configuration management feature. As a result we can easily AOP-enable any object
managed by the Spring framework. The Spring AOP module provides transaction management services for
objects in any Spring-based application. With Spring AOP we can incorporate declarative transaction
into our applications without relying on EJB components.
The Spring AOP module also introduces metadata programming to Spring. Using this we can add annotation
to the source code that instructs Spring on where and how to apply aspects.

4. Spring DAO:

The Spring`s JDBC and DAO abstraction layer offers a meaningful exception hierarchy for managing the
database connection, exception handling and error messages thrown by different database vendors. The
exception hierarchy simplifies error handling and greatly reduces the amount of code that we need to write, such
as opening and closing connections. This module also provide transaction management services for objects in a
spring application.

5. Spring ORM:

The Spring framework can be integrated to several ORM frameworks to provide Object Relational tool,
including JDO, Hibernate, OJB and iBatis SQL Maps.

6. Spring Web:

The Web context module builds on top of the application context module, providing contexts for Web-based
applications. As a result, the Spring framework supports integration with Jakarta Struts, JSF and webworks.
The Web module also eases the tasks of handling multipart requests and binding request parameters to domain

7. Spring Web MVC:

The MVC framework is a full-featured MVC implementation for building Web applications. The MVC
framework is highly configurable via strategy interfaces and accommodates numerous view technologies
including JSP, Velocity, Tiles and the generation of PDF and Excel Files

;-) There is a great variety of technologies in the web-tier like MVC PATTERN, STRUTS, JSF, WEB-WORK,
JSP, TAPESTRY, FREEMARKER etc. Developers are now puzzled and confused about the relative merits and
demerits of all these. Once they choose a technology and start implementing and later want to change over to
another technology, it is very difficult. But, as Spring offers modules for all the above technologies, it is most
often simply changing the configuration file. With this approach, it is even possible for a development team to
try and test a given task in all the above forms and see the effect and performance before deciding the choice.
Spring offers its own version of MVC architecture. It also offers adapters for Struts.

Understanding Inversion of Control (IoC)

String Framework

Spring is based on dependency injection type of IoC
– We don`t directly connect our components and
services together in code but describe which services are needed by which components in a configuration file.

1. Dependency Lookup (service locator):
You take a dependency, wrap it in an interface, register it in a dictionary, and then look it up using a helper
class called a locator. The class needs a application server environment as it is dependent on JNDI and it is
hard to test as we need to provide a dummy JNDI context for testing purpose.

A ServiceLocator acts as a central point for obtaining and caching EJBHome references:

private OrderService getOrderService() {
    OrderServiceHome home = ServiceLocator.locate(OrderServiceHome);
    OrderService orderService = home.create();

Here is the problem, we always have to explicitly look up our services in our code.

2. Dependency Injection:
In this application objects is not responsible for looking up resources they depend on. Instead IoC container
configures the object externalizing resource lookup from application code into the container. That is,
dependencies are injected into objects. Thus lookups are completely removed from application objects and it
can be used outside the container also.

private OrderService orderService;
    public void doRequest(HttpServletRequest request) {
        Order order = createOrder(request);
    public void setOrderService(OrderService orderService) {
        this.orderService = orderService;

No lookup code! The reference to OrderService is given to our class by the Spring container through the
setOrderService() method. With Spring, we never have to trouble ourselves with fetching our dependencies