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/geekmantra.com/contact/connect.php on line 2
Free Online Spring Architecture Tutorials in Springs,Spring Architecture in Springs
GeekMantra
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/geekmantra.com/contact/connect.php on line 2
J2SE [Java 2 Standard Edition]
Core Java Introduction
Exception Handling
Collection & Util Classes
Multithreading
Input & Output Streams
Applet
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)
Miscellneous
Monthly News Letter
Free SCJP Samples
Interviews Questions For Freshers
Interviews Questions For Experinced
Most Visited Links
Most Freaky Links
Advertisements

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/geekmantra.com/contact/connect.php on line 2

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
Control)
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
management
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
objects.

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);
        orderService.createOrder(order);
    }
    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

Spring Container

It manages the life cycle and configuration of application objects. We can configure how each of our beans
should be created either to create a single instance of bean or produce a new instance every time and how they
should be associated with each other. The Spring comes with two distinct containers:

    1. Bean Factories – defined by "org.springframework.beans.factory.BeanFactory" are the simplest
    containers, providing support for dependency injection.
 
   2. Application contexts –
defined by "org.springframework.context.ApplicationContext" provides
    application framework services.

Bean Factory:
Bean factory is an implementation of the factory design pattern and its function is to create and dispense beans.
As the bean factory knows about many objects within an application, it is able to create association between
collaborating objects as they are instantiated. This removes the burden of configuration from the bean and the
client.
There are several implementation of BeanFactory. The most useful one is
"org.springframework.beans.factory.xml.XmlBeanFactory". It loads its beans based on the definition
contained in an XML file. To create an XmlBeanFactory, pass an InputStream to the constructor. The
resource will provide the XML to the factory.
   
    BeanFactory factory = new XmlBeanFactory(new FileInputStream("myBean.xml"));


This line tells the bean factory to read the bean definition from the XML file. The bean definition includes the
description of beans and their properties. But the bean factory doesn`t instantiate the bean yet. To retrieve a bean
from a `BeanFactory`, the getBean() method is called. When getBean() method is called, factory will instantiate
the bean and begin setting the bean`s properties using dependency injection.

    myBean bean1 = (myBean)factory.getBean("myBean");