java spring framework

22
Overview of Spring Framework Rajeev Gupta M. Tech. CS [email protected]

Upload: rajiv-gupta

Post on 11-May-2015

921 views

Category:

Education


4 download

DESCRIPTION

Spring 3.0 framework Introduction

TRANSCRIPT

Page 1: Java spring framework

Overview of Spring Framework

Rajeev Gupta

M. Tech. CS

[email protected]

Page 2: Java spring framework

Objective

• Introduction to Spring framework

• Spring module

• Spring architecture

• Introduction to DI

• Introduction to AOP

[email protected]

Page 3: Java spring framework

Spring Framework

• Spring Framework is focused on simplifying enterprise Java development through

1. dependency injection

2. aspect-oriented programming

3. boiler-plate reduction.

[email protected]

Page 4: Java spring framework

Spring Modules

Core

AOP

DAO ORM JEE Web

[email protected]

Page 5: Java spring framework

Bean

• Objects that are managed by the Spring container are called beans.

• A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container.

• Beans, and the dependencies among them, are reflected in the configuration metadata used by a container.

– BeanFactory provides the configuration framework and basic functionality, and the

– ApplicationContext adds more enterprise-specific functionality

[email protected]

Page 6: Java spring framework

CORE SPRING CONTAINER

• Container manages how the beans in a Spring-enabled application are created, configured, and managed.

• Within this module you’ll find the Spring bean factory, which is the portion of Spring that provides dependency injection.

• In addition to the bean factory and application context, this module also supplies many enterprise services such as email, JNDI access, EJB integration, and scheduling.

[email protected]

Page 7: Java spring framework

SPRING’S AOP MODULE

• AOP module serves as the basis for developing your own aspects for your Spring-enabled application.

• Like DI, AOP supports loose coupling of application objects.

• But with AOP, application-wide concerns (such as transactions and security) are decoupled from the objects to which they’re applied.

[email protected]

Page 8: Java spring framework

DATA ACCESS DAO

• Spring’s template-based JDBC abstraction can greatly simplify JDBC code

• This module also builds a layer of meaningful exceptions on top of the error messages given by several database servers.

• Spring provide hooks into several popular ORM frameworks, including Hibernate, Java Persistence API, Java Data Objects, and iBATIS SQL Maps.

• Spring’s AOP module provide transaction management services for objects in a Spring application

[email protected]

Page 9: Java spring framework

WEB AND REMOTING

• Spring provide capable MVC framework that promotes Spring’s loosely coupled techniques in the web layer of an application

• This framework comes in two forms: – a servlet-based framework

• for conventional web applications and

– portlet-based application

• for developing against the Java portlet API.

• Spring has remoting capabilities include Remote Method Invocation (RMI), JAX-WS

[email protected]

Page 10: Java spring framework

What is Spring?

Spring is a container and it manages the lifecycle and configuration of application object i.e. called Spring

beans

This make spring a container running within an container (ie JVM or web container)

Spring is supposed to less complex framework then provided by framework such as EJB

Thus bean is less complex EJB!!!

[email protected]

Page 11: Java spring framework

Spring as an container…

[email protected]

Page 12: Java spring framework

In a Spring application, objects are created, wired together, and live within the Spring container

[email protected]

Page 13: Java spring framework

In a Spring application, objects are created, wired together, and live within the Spring container

[email protected]

Page 14: Java spring framework

• In a Spring-based application, your application objects will live within the Spring container.

• Container will create the objects, wire them together, configure them, and manage their complete lifecycle from cradle to grave (or new to finalize(), as the case may be).

• The container is at the core of the Spring Framework.

• Spring’s container uses dependency injection (DI) to manage the components that make up an application.

• This includes creating associations between collaborating components. As such, these objects are cleaner and easier to understand, support reuse, and are easy to unit test

[email protected]

Page 15: Java spring framework

Two important bean containers

• org.springframework.beans.factory.BeanFactory

• org.springframework.context.ApplicationContext

[email protected]

Page 16: Java spring framework

Two type of container

• Bean factories • defined by the org.springframework.beans.factory.BeanFactory

interface) are the simplest of containers.

• Bean factories provides basic support for DI.

• Application contexts • defined by the org.springframework.context.ApplicationContext

interface.

• Application context build on the notion of a bean factory by providing application framework services, such as the ability to resolve textual messages from a properties file and the ability to publish application events to interested event listeners

[email protected]

Page 17: Java spring framework

BeanFactory

• Factory design pattern.

BeanFactory factory =new XmlBeanFactory(new FileSystemResource(“e:/spring/beans.xml"));

[email protected]

Page 18: Java spring framework

ApplicationContext

An application context gives more:

• Support for I18N(Internationalization) for messages.

• Provides generic way to load resources.

• Publish events to beans registered as events.

[email protected]

Page 19: Java spring framework

ApplicationContext

• ClassPathXmlApplicationContext - XML file located in the classpath

• FileSystemXmlApplicationContext - XML file in the file system

• XmlWebApplicationContext - XML file

contained within a web application

[email protected]

Page 20: Java spring framework

ApplicationContext

• ApplicationContext context = new FileSystemXmlApplicationContext("c:/foo.xml");

• ApplicationContext context = new ClassPathXmlApplicationContext("foo.xml");

[email protected]

Page 21: Java spring framework

Beans Life cycle

Above Figure is from Spring in action book, Manning [email protected]

Page 22: Java spring framework

ApplicationContext – Bean Life Cycle

Above Figure is from Spring in action book, Manning publications

[email protected]