ArticlesTutorialsInterview Questions & AnswersCertificationsFree Books & Sample ChaptersTechnical Discussions  Your Account | Advertise with us | Feedback |
Few pages of this site are under construction and we are constantly trying to improve it. If you have any suggestions or ideas about how to improve the site, please Let us know.
Spring Framework Tutorials
ォ Previous | 1 2 |Next サ

Contents
The Spring framework overview
Spring framwork modules
Inversion of Control or Dependency Injection in Spring
Inversion of Control Example
    Code Listing 1 (HelloService Interface)
    Code Listing 2 (ByeService Interface )
     Code Listing 3 (HelloBean Class )
    Code Listing 4 (hello.xml config file)
    Code Listing 5 (TestClient Class)
Resources & Downloads

The Spring framework overview:

Spring is the de-facto standard in lightweight enterprise application framework. Spring is an open source framework created to address the complexity of enterprise application development. One of the main advantages of the Spring framework is its layered architecture, which allows you to be selective about which of its components you use while also providing a consistent framework for J2EE application development.

However Spring痴 usefulness isn稚 limited to server-side development. Any Java application can benefit from Spring in terms of simplicity, testability, and loose coupling.


Spring framwork modules:

The Spring framework is a layered architecture consisting of seven well-defined modules. The Spring modules are built on top of the core container, which defines how beans are created, configured, and managed, as shown in following figure.

Each of the modules or components that consist of the Spring framework can stand on its own or be implemented jointly with one or more of the other modules or components. The description of each component is as follows:

  1. The core container:

    The core container provides the fundamental functionality of the Spring framework. In this module primary component is the BeanFactory, an implementation of the Factory pattern. The BeanFactory applies the Inversion of Control (IOC) pattern to separate an application's configuration and dependency specification from the actual application code.

  2. Spring context module :

    TThe Spring context is a configuration file that provides context information to the Spring framework. The Spring context includes enterprise services such as e-mail, JNDI, EJB, internalization, validation, scheduling and applications lifecycle events. Also included is support for the integration with templating frameworks such as velocity.

  3. Spring AOP module:

    The Spring AOP module allows a software component to be decorated with additional behavior, through its configuration management feature. As a result you 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 you can incorporate declarative transaction management into your applications without relying on EJB components.

  4. Spring DAO module:

    The Spring DAO module provides a JDBC-abstraction layer that reduces the need to do tedious JDBC coding and parsing of database-vendor specific error codes. Also, the JDBC package provides a way to do programmatic as well as declarative transaction management, not only for classes implementing special interfaces, but for all your POJOs (plain old Java objects).

  5. Spring ORM module:

    : Spring provides integration with OR mapping tools like Hibernate, JDO and iBATIS. Spring transaction management supports each of these ORM frameworks as well as JDBC.

  6. Spring Web module:

    The Web context module provides basic web-oriented integration features 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. The Web module also eases the tasks of handling multi-part requests and binding request parameters to domain objects.

  7. Spring MVC framework module:

    Spring provides a pluggable MVC architecture. The users have a choice to use the web framework or continue to use their existing web framework. Spring separates the roles of the controller; the model object, the dispatcher and the handler object which makes it easier to customize them. Spring web framework is view agnostic and does not push the user to use only JSPs for the view. The user has the flexibility to use JSPs, XSLT, velocity templates etc to provide the view.

Back to top

Inversion of Control (Dependency Injection):

Inversion of control is at the heart of the Spring framework. The basic concept of the Inversion of Control pattern (also known as dependency injection) is that you do not create your objects but describe how they should be created. You don't directly connect your components and services together in code but describe which services are needed by which components in a configuration file. A container (in the case of the Spring framework, the IOC container) is then responsible for hooking it all up.

The easiest way to understand inversion of control is to see it in example. This basic Spring example demonstrates how you can inject application dependencies through the Spring IOC container.


Inversion of Control Example:

It is a simple code for wishing hello and bye. We have two interfaces HelloInterface and ByeInterface as listed below:

Code Listing 1. HelloService Interface   (See Implementation)

 
package com.developersBook.springExample.service;

import com.developersBook.springExample.domain.Name;

public interface HelloService {
	public String sayHello(Name name);
}

Code Listing 2. ByeService Interface   (See Implementation)

 
package com.developersBook.springExample.service;

import com.developersBook.springExample.domain.Name;

public interface ByeService {
	public String sayBye(Name name);
}

Back to top

ォ Previous | 1 2 |Next サ
Related Links

  ALSO SEE :

About Us | Our Mission | Terms of use | Author Terms |    Search        | Contact Us | Advertise With Us | Link to Us | Sitemap
Copyright © 2008 developersBOOK.COM. All rights reserved.