Vous êtes sur la page 1sur 20

Spring In J2EE

- Exploring Different Features of Spring

Presented by: Narayan Ubrani

HCU-JAVA ADMS : Service Offerings 1


Agenda

• What is Spring?
• Spring Web Integration Introduction
• Introduction: Spring Dependency Injection / IoC
• Transaction using Spring
• Use of Interceptors
• OR Mapping and Batch Processing with Spring
• Securing Spring Application

HCU-JAVA ADMS : Service Offerings 2


Spring Framework History

• Started 2002/2003 by Rod Johnson and Juergen


Holler
• Started as a framework developed around Rod
Johnson’s book “Expert One-on-One J2EE Design
and Development”
• Spring 1.0 Released March 2004, now at 2.4.5
• 2004/2005 Spring is emerging as a leading full-stack
Java/J2EE application framework
• Spring Framework is response to the complexity of
Enterprise JavaBeans

HCU-JAVA ADMS : Service Offerings 3


What is Spring ?

Spring is lightweight non-intrusive framework which


addresses various tiers in a J2EE application.

Business tier Data Access tier


Presentation tier
Lightweight IoC Data Persistence
Spring Web MVC with Hibernate,
container with
Framework SQLMaps and JDBC
support for AOP-
Integration Batch Processing
driven interceptors
-Struts, JSF, Jsp , with Spring.
and transaction
Rich View Support
Tier

HCU-JAVA ADMS : Service Offerings 4


Spring Framework

• Spring integrates tiers together using XML


configuration instead of hard-coding.

• Substantially reduces code, speeds up development,


facilitates easy testing and improves code quality.

• Easy integration with third party tools and


technologies

HCU-JAVA ADMS : Service Offerings 5


Dependency Injection and IoC

• Instead of objects invoking other objects, the


dependant objects are added through an external
entity/container.
• Dependency injection: dependencies are “injected”
spring container at runtime.
• Beans define their dependencies through constructor
arguments or properties
• Prevents hard-coded object creation and
object/service lookup
• Loose coupling
• Supports effective unit tests

HCU-JAVA ADMS : Service Offerings 6


Non IOC Object Service

• Instead of objects invoking other objects, the


public class CampaignServiceImpl implements
dependant objects
CampaignService { are added through an external
entity/container.
public Campaign updateCampaign(Campaign campaign)
•throws
Dependency injection: dependencies are “injected”
CampaignException{
try{
spring container at runtime.
CampaignDAO campaign = new CampaignDAOImpl();
• Beans define their dependencies through constructor
..
arguments or properties
OpportunityDAO oppDAO = new OpportunityDAOImpl();
Prevents
• // hard-coded
Alternatively, object creation
initialize and
thru factory
object/service
// OpportunityDAO lookup
oppDAO = OppFactory.getOpp();
• Loose coupling
oppDAO.save(campaign);
• ..
Supports effective unit tests
}catch(Exception e){
} Code is tightly coupled or interspersed with Factory code!
}

HCU-JAVA ADMS : Service Offerings 7


Spring IOC Service

public class CampaignServiceImpl implements


CampaignService {
public Campaign updateCampaign(Campaign campaign)
throws CampaignException{
try{
oppDAO.save(campaign);

}catch(Exception e){
}
}
// Spring sets the value thru runtime injection!
private setOpportunityDAO(OpportunityDAO oppDao){
this.oppDAO = oppDao;
}

HCU-JAVA ADMS : Service Offerings 8


Spring IOC Configuration

• <bean name=“CampaignService”
class=“com.zatyam.rms.CampaignServiceImpl”>
• <property name=“OpportunityDAO”>

• <ref bean=“oppDao”/>
• </property>
• </bean>

HCU-JAVA ADMS : Service Offerings 9


Spring MVC

• Request-response based web application framework,


such as Struts and WebWork
• Flexible and extensible via component’s interfaces
• Simplifies testing through Dependency Injection
• Simplifies form handling through its parameter
binding, validation and error handling
• Abstracts view technology (JSP, Velocity, FreeMarker
Excel , PDF)

HCU-JAVA ADMS : Service Offerings 10


Spring MVC Architecture

HCU-JAVA ADMS : Service Offerings 11


Spring MVC over Struts framework

• Spring has a rich selection of Controller


implementations . We get to choose the controller
implementation that best suits our needs. In Struts,
we only have the Action class and if we need
something more powerful, we have to subclass
Action and implement it yourself.
• In Spring there is no need of Value Object
Implementation. You can just use single POJO in
different layers. And in Struts you end up creating
about 3 objects in three different layers

HCU-JAVA ADMS : Service Offerings 12


Use of Interceptors

• Interceptors are useful for common services:


security, traffic logging, and perhaps front-end
common data validation
– Implement the HandlerInterceptor Interface
– Simply wire your implemented Interceptors into the
HandlerMapping
• Out of the-box implementations exist:
– Locale, Theme, …more
• Spring Interceptors are called at controllers as well as
at service layer

HCU-JAVA ADMS : Service Offerings 13


Transactions in Spring

• Spring has rich support for transaction management,


both programmatic and declarative.
• Spring’s support for declarative transaction
management is implemented through Spring’s AOP
framework.
• The Spring AOP framework makes use of an AOP-
enabled Spring bean factory.
• Transactions are demarcated by specifying
transaction characteristics at the component service
level, in a Spring-specific configuration file
HCU-JAVA ADMS : Service Offerings 14
Salient Features of Spring Transaction

• Lightweight containers for transaction handling


without the necessity of having a full-blown
application server.
• No mixup of business logic code with infrastructure-
level code. Spring manages transaction declarative
with which we can externalize transaction control to
configuration files.
• Spring and Hibernate—can be combined to
effectively control transactions across multi-vendor
databases

HCU-JAVA ADMS : Service Offerings 15


Spring ORM Framework Support
• Spring provides integration for Sun’s standard
persistence API JDO, as well as the open source ORM
frameworks Hibernate, Apache OJB, and iBATIS SQL
Maps
• Hibernate tool doing most of the actual persistence
Spring provides integration points to Hibernate
frameworks as well as some additional services:
• Integrated transaction management
• Exception handling
• Thread-safe, lightweight template classes
• Connection Pooling and Resource Management

HCU-JAVA ADMS : Service Offerings 16


Spring Batch Process
• Spring Batch is a lightweight, comprehensive batch
framework designed to enable the development of
robust batch applications vital for the daily operations of
enterprise systems
• Spring Batch builds upon the productivity, POJO-based
development approach, and general ease of use
capabilities of spring framework.
• Spring Batch supports efficient processing of really large
batch jobs (100K - 1000K records) through parallel
processing

HCU-JAVA ADMS : Service Offerings 17


Securing Spring Applications
• Spring provides collection of beans that are configured
within a Spring application context, taking full advantage
of Spring’s support for dependency injection and aspect-
oriented programming . Using these beans you can do:
• Encrypt passwords
• Cache User Information
• Authenticating against databases and LDAP
Also Spring uses ageci security framework with uses
servlet filters that intercept servlet requests to perform
authentication and enforce security

HCU-JAVA ADMS : Service Offerings 18


Spring supports More …
• Spring supports for Workflow Engine: Sequencing the
activities.
• Spring has support for JMS: Sending and Receiving
Messages.
• And More……..

HCU-JAVA ADMS : Service Offerings 19


Thank You!!

My contact details :
narayan_ubrani@satyam.com

HCU-JAVA ADMS : Service Offerings 20

Vous aimerez peut-être aussi