SlideShare a Scribd company logo
1 of 65
Introduction to the
Spring Framework
By Mumbai Academics
Advantages of Spring Framework Architecture
There are many advantages of Spring Framework. They are as
follows:
 Lightweight: Spring framework is lightweight because of its
POJO implementation. The Spring Framework doesn't force
the programmer to inherit any class or implement any
interface. That is why it is said non-invasive, Enable you to
write powerful, scalable applications using POJOs.
 Easy to develop JavaEE application: The Dependency
Injection feature of Spring Framework and it support to
various frameworks makes the easy development of JavaEE
application.
 Easy to test: The Dependency Injection makes easier to
test the application. The EJB or Struts application require
server to run the application but Spring framework doesn't
require server.










Loose Coupling: The Spring applications are loosely
coupled because of dependency injection and handles
injecting dependent components without a component
knowing where they came from (IoC).
Powerful abstraction: It provides powerful abstraction to
JavaEE specifications such as JMS, JDBC, JPA and JTA.
Declarative support: It provides declarative support for
caching, validation, transactions and formatting.
Portable :can use server-side in web/ejb app, client-side in
swing app, business logic is completely portable.
Cross-cutting behavior : Resource Management is crosscutting concern, easy to copy-and-paste everywhere.




Configuration information: Spring provides one consistent
way of configuring everything, separate configuration from
application logic, varying configuration.
Lifecycle : Responsible for managing all your application
components, particularly those in the middle tier container
sees components through well-defined lifecycle: init(),
destroy()
Spring


A popular and stable Java application framework for
enterprise development






Ubiquitous for Java development
Well established in enterprise Java apps
Time tested and proven reliable

A primary purpose is to reduce dependencies and
even introduce negative dependencies
 Different from almost every other framework out
there
 Part of the reason it has been adopted so quickly
 Spring code base is proven to be well structured
(possibly the best)
 139 packages
 No dependency cycles
Spring


A lightweight framework that addresses each tier in a
Web application.




Presentation layer – An MVC framework that is most similar
to Struts but is more powerful and easy to use.
Business layer – Lightweight IoC container and AOP support
(including built in aspects)
Persistence layer – DAO template support for popular ORMs
and JDBC









Simplifies persistence frameworks and JDBC
Complimentary: Not a replacement for a persistence framework

Helps organize your middle tier and handle typical
J2EE plumbing problems.
Solutions to typical coding busywork
 JDBC ,LDAP,Web Services
Reduces code and speeds up development
Current Version is 3.0
Spring (continued)












Do I have to use all components of Spring?
Spring is a non-invasive and portable framework that
allows you to introduce as much or as little as you
want to your application.
Promotes decoupling and reusability
POJO Based
Allows developers to focus more on reused business
logic and less on plumbing problems.
Reduces or alleviates code littering, ad hoc
singletons, factories, service locators and multiple
configuration files.
Removes common code issues like leaking
connections and more.
Built in aspects such as transaction management
Most business objects in Spring apps do not depend
on the Spring framework.
Why Did I choose Spring?














Introduced to Spring by way of Hibernate
Spring is an open source layered Java/J2EE
application framework
The Spring Framework is licensed under the terms of
the Apache License
Originally wanted Spring to provide a way to simplify
DAO objects and provide declarative transaction
support to our non-EJB applications.
Needed a solution to loosely couple business logic in
a POJO fashion.
Wanted to build portable applications that provided
clearer separation of presentation, business, and
persistence logic.
Easily integrated with our existing frameworks
Great documentation and community support
Spring Mission Statement











J2EE should be easier to use
It's best to program to interfaces, rather than classes. Spring
reduces the complexity cost of using interfaces to zero.
JavaBeans offer a great way of configuring applications
OO design is more important than any implementation
technology, such as J2EE
Checked exceptions are overused in Java. A framework
shouldn't force you to catch exceptions you're unlikely to be
able to recover from.
Testability is essential, and a framework such as Spring
should help make your code easier to test
Spring should be a pleasure to use
Your application code should not depend on Spring APIs
Spring should not compete with good existing solutions, but
should foster integration. (For example, JDO and Hibernate
are great O/R mapping solutions. Don't need to develop
another one).
Simplify your code with Spring



Enables you to stop polluting code
No more custom singleton objects









Beans are defined in a centralized configuration file

No more custom factory object to build and/or locate other
objects
DAO simplification
 Consistent CRUD
 Data access templates
 No more copy-paste try/catch/finally blocks
 No more passing Connection objects between methods
 No more leaked connections
POJO Based
Refactoring experience with Spring
Caution Spring is addictive!
Modules of the Spring Framework








The Spring Framework can be considered as a collection
of frameworks-in-the-framework:
Core - Inversion of Control (IoC) and Dependency
Injection.
AOP :- These modules support aspect oriented
programming implementation where you can use Advices,
Pointcuts etc. to decouple the code.
DAO - Data Access Object support, transaction
management, JDBC-abstraction
ORM - Object Relational Mapping data access, integration
layers for JPA, JDO, Hibernate, and iBatis
MVC - Model-View-Controller implementation for webapplications
Context-This module supports internationalization (I18N),
EJB,Remote Access, Authentication and Authorization,
Remote Management like RMI,HTTP Invoker,Hessain,
Messaging Framework, Web Services, Email, Testing, …
Modules of the Spring Framework


Expression Language:- It is an extension to the EL
defined in JSP. It provides support to setting and getting
property values, method invocation, accessing collections
and indexers, named variables, logical and arithmetic
operators, retrieval of objects by name etc.
Overview of the Spring Framework

Very loosely coupled, components widely reusable and
separately packaged.
Spring Details






Spring allows to decouple software layers by injecting a
component’s dependencies at runtime rather than having
them declared at compile time via importing and
instantiating classes.
Spring provides integration for J2EE services such as EJB,
JDBC, JNDI, JMS, JTA. It also integrates several popular
ORM toolkits such as Hibernate and JDO and assorted
other services as well.
One of the highly touted features is declarative transactions,
which allows the developer to write transaction-unaware
code and configure transactions in Spring config files.
Spring Details




Spring is built on the principle of unchecked exception
handling. This also reduces code dependencies between
layers. Spring provides a granular exception hierarchy for
data access operations and maps JDBC, EJB, and ORM
exceptions to Spring exceptions so that applications can get
better information about the error condition.
With highly decoupled software layers and programming to
interfaces, each layer is easier to test. Mock objects is a
testing pattern that is very useful in this regard.
Spring Solutions
•

Solutions address major J2EE problem areas:
•
•
•
•
•

•
•

Web application development (MVC)
Enterprise Java Beans (EJB, JNDI)
Database access (JDBC, iBatis, ORM)
Transaction management (JTA, Hibernate, JDBC)
Remote access (Web Services, RMI)

Each solution builds on the core architecture
Solutions foster integration, they do not re-invent
the wheel
How to Start Using Spring






create the class
create the xml file to provide the values
create the test class
Load the spring jar files
Run the test class
Create Java class
Create the xml file
Create the test class
Load the jar files required for
spring framework
There are mainly three jar files required to run this
application.
 org.springframework.core-3.0.1.RELEASE-A
 com.springsource.org.apache.commons.logging-1.1.1
 org.springframework.beans-3.0.1.RELEASE-A
What are Lightweight Frameworks?
•
•
•

Non-intrusive
No container requirements
Simplify application development
Remove re-occurring pattern code
• Productivity friendly
• Unit test friendly
•

•
•
•

Very pluggable
Usually open source
Examples:
•
•
•
•
•

Spring, Pico, Hivemind
Hibernate, IBatis, Castor
WebWork
Quartz
Sitemesh
Spring IoC + AOP


IoC container







Setter based and constructor based dependency injection
Portable across application servers
Promotes good use of OO practices such as programming
to interfaces.
Beans managed by an IoC container are reusable and
decoupled from business logic

AOP






Spring uses Dynamic AOP Proxy objects to provide crosscutting services
Reusable components
Aopalliance support today
Integrates with the IoC container
AspectJ support in Spring 1.1
Spring IoC
Inversion of Control









Dependency injection
 Beans define their dependencies through
constructor arguments or properties
 The container provides the injection at runtime
Decouples object creators and locators from
application logic
Easy to maintain and reuse
Testing is easier
Useful for separating dao and business layer
Useful for separating controllers and business layer
The code is more extensible, easier to read, and
modules/layers can easily be replaced
Non-IoC / Dependency Injection
Non-IoC Service Object
public class OrderServiceImpl implements
IOrderService {
public Order saveOrder(Order order) throws
OrderException{
try{
// 1. Create a Session/Connection object
// 2. Start a transaction
// 3. Lookup and invoke one of the methods in a
// DAO and pass the Session/Connection object.
// 4. Commit transaction
}catch(Exception e){
// handle e, rollback transaction,
//cleanup, // throw e
}finally{
//Release resources and handle more exceptions
}

}
IoC / Dependency Injection
IoC Service Object

public class OrderSpringService
implements IOrderService {
IOrderDAO orderDAO;
public Order saveOrder(Order order)
throws OrderException{
// perform some business logic…
return orderDAO.saveNewOrder(order);
}
public void setOrderDAO(IOrderDAO
orderDAO) {
this.orderDAO = orderDAO;
}


Program to interfaces for your bean dependencies!
Spring Bean Definition

Typical java bean with a unique id
 In spring there are basically two types


 Singleton


One instance of the bean created and
referenced each time it is requested

 Prototype

(non-singleton)

New bean created each time
 Same as new ClassName()




Beans are normally created by Spring
as late as possible
Spring Bean Definition





The bean class is the actual implementation of the
bean being described by the BeanFactory.
Bean examples – DAO, DataSource, Transaction
Manager, Persistence Managers, Service objects, etc
Spring config contains implementation classes while
your code should program to interfaces.
Bean behaviors include:
 Singleton or prototype
 Autowiring
 Initialization and destruction methods





init-method
destroy-method

Beans can be configured to have property values set.


Can read simple values, collections, maps, references to
other beans, etc.
What is a bean definition?


Defines a bean for Spring to manage
 Key











attributes

class (required): fully qualified java class name
id: the unique identifier for this bean
configuration: (singleton, init-method, etc.)
constructor-arg: arguments to pass to the constructor at
creation time
property: arguments to pass to the bean setters at
creation time
Collaborators: other beans needed in this bean (a.k.a
dependencies), specified in property or constructor-arg

Typically defined in an XML file
Simple Spring Bean Example


<bean id=“orderBean” class=“example.OrderBean”
init-method=“init”>
<property
name=“minimumAmountToProcess”>10</property>
<property name=“orderDAO”>
<ref bean=“orderDAOBean”/>
</property>
</bean>



public class OrderBean implements IOrderBean{
…
public void
setMinimumAmountToProcess(double d){
this. minimumAmountToProcess = d;
}
public void setOrderDAO(IOrderDAO odao){
this.orderDAO = odao;
}
}
Spring BeanFactory


BeanFactory is core to the Spring framework









Lightweight container that loads bean definitions and
manages your beans.
Configured declaratively using an XML file, or files, that
determine how beans can be referenced and wired together.
Knows how to serve and manage a singleton or prototype
defined bean
Responsible for lifecycle methods.
Injects dependencies into defined beans when served

Avoids the use of singletons and factories
Spring uses a BeanFactory to create,
manage and locate “beans” which are
basically instances of a class
 Typical

usage is an XML bean factory which
allows configuration via XML files
Spring ApplicationContext





A Spring ApplicationContext allows you to get access
to the objects that are configured in a BeanFactory in
a framework manner.
ApplicationContext extends BeanFactory





Several ways to configure a context:






Adds services such as international messaging capabilities.
Add the ability to load file resources in a generic fashion.
XMLWebApplicationContext – Configuration for a web
application.
ClassPathXMLApplicationContext – standalone XML
application context
FileSystemXmlApplicationContext

Allows you to avoid writing Service Locators
Configuring an XMLWebApplicationContext
<context-param>
<param-name>contextConfigLocation</paramname>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoader
Listener
</listener-class>
</listener>
Configuring an XMLWebApplicationContext
<context-param>
<param-name>contextConfigLocation</paramname>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoader
Servlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
Spring AOP
Spring AOP







Framework that builds on the aopalliance interfaces.
Aspects are coded with pure Java code. You do not
need to learn pointcut query languages that are
available in other AOP implementations.
Separates the core business code from the aspects
we wrap around it: security, transaction management,
monitering,logging…
Spring aspects can be configured using its own IoC
container.






Objects obtained from the IoC container can be
transparently advised based on configuration

Spring AOP has built in aspects such as providing
transaction management, performance monitoring
and more for your beans
Spring AOP is not as robust as some other
implementations such as AspectJ.


However, it does support common aspect uses to solve
Spring AOP


Attempts to separate concerns, increase
modularity, and decrease redundancy
 Separation


Break up features to minimize overlap

 Don’t


of Concerns (SoC)

Repeat Yourself (DRY)

Minimize code duplication

 Cross-Cutting




Concerns

Program aspects that affect many others (e.g. logging)

AspectJ is the top AOP package
Spring AOP


Supports the following advices:












method before
method after returning
throws advice
around advice (uses AOPAlliance MethodInterceptor directly)

Spring allows you to chain together interceptors and
advice with precedence.
Aspects are weaved together at runtime. AspectJ uses
compile time weaving.
Spring AOP also includes advisors that contain advice
and pointcut filtering.
ProxyFactoryBean – sources AOP proxies from a Spring
BeanFactory
IoC + AOP is a great combination that is non-invasive
Through AOP, we add transversal functionalities to
objects (ie not directly related to the code it contains)
2. Spring principles: AOP


Without AOP



With AOP
2. Spring principles: AOP
Useful for automatic handling of transaction
with Hibernate
 Useful for Acegi (automatic credentials
checking before executing some methods)
 Code smaller, easier to read (not polluted
by transversal aspects not directly relevant)

Spring Database Components
Consistent Abstract Classes for DAO Support



Extend your DAO classes with the proper xxxDAOSupport class
that matches your persistence mechanism.
JdbcDaoSupport
Super class for JDBC data access objects.
 Requires a DataSource to be set, providing a JdbcTemplate based
on it to subclasses.




HibernateDaoSupport
Super class for Hibernate data access objects.
 Requires a SessionFactory to be set, providing a
HibernateTemplate based on it to subclasses.




JdoDaoSupport
Super class for JDO data access objects.
 Requires a PersistenceManagerFactory to be set, providing a
JdoTemplate based on it to subclasses.




SqlMapDaoSupport
Supper class for iBATIS SqlMap data access object.
 Requires a DataSource to be set, providing a SqlMapTemplate

Spring DAO Templates









Built in code templates that support JDBC, Hibernate,
JDO, and iBatis SQL Maps
Simplifies data access coding by reducing redundant
code and helps avoid common errors.
Alleviates opening and closing connections in your
DAO code.
No more ThreadLocal or passing Connection/Session
objects.
Transaction management is handled by a wired bean
You are dropped into the template with the resources
you need for data access – Session,
PreparedStatement, etc.
Code only needs to be implemented in callback
methods.




doInXXX(Object)

Optional separate JDBC framework
Ex: Code without a template
public class OrderHibernateDAO implements IOrderDAO {
public Order saveOrder(Order order) throws
OrderException{
Session s = null;
Transaction tx = null;
try{
s = ... // get a new Session object
tx = s.beginTransaction();
s.save(order);
tx.commit();
} catch (HibernateException he){
// log, rollback, and convert to OrderException
} catch (SQLException sqle){
// log, rollback, and convert to OrderException
} finally {
s.close(); // needs a try/catch block
}
return order;
}
Ex: Spring DAO Template Example
public class OrderHibernateDAO extends HibernateDaoSupport
implements IOrderDAO {
...
public Order saveOrder(final Order order) {
return (Order) getHibernateTemplate().execute(new
HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
session.save(order);
return order;
}
});
}
...
}
Consistent Exception Handling


Spring has it’s own exception handling hierarchy for DAO logic.



No more copy and pasting redundant exception logic!



Exceptions from JDBC, or a supported ORM, are wrapped up
into an appropriate, and consistent, DataAccessException and
thrown.



This allows you to decouple exceptions in your business logic.



These exceptions are treated as unchecked exceptions that you
can handle in your business tier if needed. No need to try/catch
in your DAO.



Define your own exception translation by subclassing classes
such as SQLErrorCodeSQLExceptionTranslator
Spring and Testing

Easier test driven development (TDD)
 Integration testing


 Can

use a standalone Spring configuration
with mock objects for testing.
 Consider XMLApplicationContext or
FileSystemApplicationContext.


Unit testing
 Allows

you to test outside the container
without using the Spring container.



Easy to test POJOs
Spring MVC Framework
MVC Framework







Clear separation of roles: controller, validator, form object,
Dispatch servlet, View resolver, …
Extensible and adaptable
Several views of a result (pdf, excel, html, …)
Can be wired (possible to use transparently the IoC pattern).
Spring Annotation Based Controllers
Spring 2.5 introduced support for annotation based MVC
controllers. @RequestMapping, @RequestParam,
@ModelAttribute are some of the annotations provided for this
implementation.




Can be used with other frameworks: JSF, Struts,
Tapestry, Webwork
Completely transparent: no need to change anything in
what is done by these other frameworks
Benefits of the Spring Web
MVC Framework
The Spring Web MVC Framework is a robust, flexible, and
well-designed framework for rapidly developing web
applications using the MVC design pattern.The benefits
achieved from using this Spring module are similar to
those you get from the rest of the Spring Framework
Easier testing—This is a common theme you will find
across all the Spring classes.The fact that most of Spring’s
classes are designed as JavaBeans enables you to inject
test data using the setter methods of these classes. Spring
also provides mock classes to simulate Java HTTP objects
(HttpServletRequest, for example), which makes unit
testing of the web layer much simpler.
Benefits of the Spring Web
MVC Framework
Bind directly to business objects—Spring MVC does not
require your business (model) classes to extend any
special classes; this enables you to reuse your business
objects by binding them directly to the HTML forms fields. In
fact, your controller classes are the only ones that are
required to extend Spring classes (or implement a Spring
controller interface).
Clear separation of roles—Spring MVC nicely separates
the roles played by the various components that make up
this web framework. For example, when we dis-cuss
concepts such as controllers, command objects, and
validators, you will begin to see how each component
plays a distinct role.
Benefits of the Spring Web
MVC Framework
Simple but powerful tag library—Spring's tag library is
small, straightforward, but powerful. For example. Spring
uses the JSP expression language (EL) for arguments
to the <spring :bind> tag.
Web Flow—This module is a subproject and is not bundled
with the Spring core distribution. It is built on top of Spring
MVC and adds the capability to easily write wizard like
web applications that span across several HTTP requests
(an online shopping cart, for example).
Benefits of the Spring Web
MVC Framework
View technologies and web frameworks—Although we
are using JSP as our view technology. Spring supports
odier view technologies as well, such as Apache Velocity
and FreeMarker.This is a powerful concept because
switching from JSP to Velocity is a matter of configuration. Furthermore, Spring provides integration support for
Apache Struts.
■ Lighter-weight environment—As I mentioned in die
previous chapter. Spring enables you to build enterpriseready applications using FOJOs; the environment
setup can be simpler and less expensive because you
could develop and deploy your application using a lighterweight servlet container.
Features of Spring Web MVC
Spring's web module provides a wealth of unique web support
features, including:
 Clear separation of roles - controller, validator, command
object, form object, model object, DispatcherServlet, handler
mapping, view resolver, etc. Each role can be fulfilled by a
specialized object.
 Powerful and straightforward configuration of both framework
and application classes as JavaBeans, including easy
referencing across contexts, such as from web controllers to
business objects and validators.
 Adaptability, non-intrusiveness. Use whatever controller
subclass you need (plain, command, form, wizard, multi-action,
or a custom one) for a given scenario instead of deriving from a
single controller for everything.
 Reusable business code - no need for duplication. You can use
existing business objects as command or form objects instead of
mirroring them in order to extend a particular framework base
Features of Spring Web MVC

Customizable

locale and theme resolution, support for JSPs
with or without Spring tag library, support for JSTL, support for
Velocity without the need for extra bridges, etc.
 A simple yet powerful JSP tag library known as the Spring tag
library that provides support for features such as data binding
and themes. The custom tags allow for maximum flexibility in
terms of markup code. For information on the tag library
descriptor.
 A JSP form tag library, introduced in Spring 2.0, that makes
writing forms in JSP pages much easier. For information on the
tag library descriptor.
 Beans whose lifecycle is scoped to the current HTTP request
or HTTP Session. This is not a specific feature of Spring MVC
itself, but rather of the WebApplicationContext container(s) that
Spring MVC uses. These bean scopes are described in detail in
the section entitled.
Features of Spring Web MVC

Customizable binding and validation - type mismatches as
application-level validation errors that keep the offending value,
localized date and number binding, etc instead of String-only
form objects with manual parsing and conversion to business
objects.
 Customizable handler mapping and view resolution - handler
mapping and view resolution strategies range from simple URLbased configuration, to sophisticated, purpose-built resolution
strategies. This is more flexible than some web MVC
frameworks which mandate a particular technique.
 Flexible model transfer - model transfer via a name/value Map
supports easy integration with any view technology.

4. A full MVC Framework
Working Of MVC Framework







The Spring web MVC framework provides model-viewcontroller architecture and ready components that can be
used to develop flexible and loosely coupled web applications.
The MVC pattern results in separating the different aspects of
the application (input logic, business logic, and UI logic), while
providing a loose coupling between these elements.
The Model encapsulates the application data and in general
they will consist of POJO.
The View is responsible for rendering the model data and in
general it generates HTML output that the client's browser
can interpret.
The Controller is responsible for processing user requests
and building appropriate model and passes it to the view for
rendering.
The DispatcherServlet

The Spring Web model-view-controller (MVC) framework is
designed around a DispatcherServlet that handles all the
HTTP requests and responses. The request processing
workflow of the Spring Web MVC DispatcherServlet is
illustrated in the following diagram:






Following is the sequence of events corresponding to an
incoming HTTP request to DispatcherServlet:
After receiving an HTTP request, DispatcherServlet consults
the HandlerMapping to call the appropriate Controller.
The Controller takes the request and calls the appropriate
service methods based on used GET or POST method. The
service method will set model data based on defined business
logic and returns view name to the DispatcherServlet.
The DispatcherServlet will take help from ViewResolver to
pickup the defined view for the request.
Once view is finalized, The DispatcherServlet passes the
model data to the view which is finally rendered on the
browser.

All the above mentioned components ie. HandlerMapping, Controller and ViewResolver are parts
ofWebApplicationContext which is an extension of the plain ApplicationContext with some
extra features necessary for web applications.
Even More Spring Components







JavaMail helpers
Many ORM tools are supported: Hibernate, JDO, Apache
OJB, iBATIS
Templates using IoC to reduce the amount of code in the
DAO objects
Scheduling support via Quartz
Convenience implementation classes for





Remoting support – JAXRPC, RMI, Hessian, and Burlap

EJB support for easier access.
Acegi Security System for Spring






http://acegisecurity.sourceforge.net/
Very good framework!

Eclipse Plugin – Spring IDE for Eclipse
Coming soon



JMS implementation classes
JMX support

More Related Content

What's hot

Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Examplekamal kotecha
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API07.pallav
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architectureAnurag
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - CoreDzmitry Naskou
 
Spring Framework
Spring FrameworkSpring Framework
Spring Frameworknomykk
 
Spring boot
Spring bootSpring boot
Spring bootsdeeg
 
Spring framework Introduction
Spring framework IntroductionSpring framework Introduction
Spring framework IntroductionAnuj Singh Rajput
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introductionJonathan Holloway
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)slire
 
Hibernate
HibernateHibernate
HibernateAjay K
 

What's hot (20)

Spring beans
Spring beansSpring beans
Spring beans
 
Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Example
 
Spring Core
Spring CoreSpring Core
Spring Core
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architecture
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring boot
Spring bootSpring boot
Spring boot
 
Java Spring Framework
Java Spring FrameworkJava Spring Framework
Java Spring Framework
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
Spring framework Introduction
Spring framework IntroductionSpring framework Introduction
Spring framework Introduction
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 
Servlets
ServletsServlets
Servlets
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
Hibernate
HibernateHibernate
Hibernate
 
Hibernate in Action
Hibernate in ActionHibernate in Action
Hibernate in Action
 

Viewers also liked

Springs & uses of springs
Springs & uses of springsSprings & uses of springs
Springs & uses of springsSazed Salman
 
Types of springs Design Machine Elements (DME)
Types of springs Design Machine Elements (DME)Types of springs Design Machine Elements (DME)
Types of springs Design Machine Elements (DME)Amit Mak
 
mechanical springs
mechanical springsmechanical springs
mechanical springshussain741
 
Design of helical spring against static loading
Design of helical spring against static loadingDesign of helical spring against static loading
Design of helical spring against static loadingakashpatel281996
 
Springs-mechanical engineering
Springs-mechanical engineeringSprings-mechanical engineering
Springs-mechanical engineeringNikhil Kumar
 
Design of mechanical spring
Design of mechanical springDesign of mechanical spring
Design of mechanical springTheEngineer13
 
Cyber Crime and Cyber Security
Cyber Crime and Cyber SecurityCyber Crime and Cyber Security
Cyber Crime and Cyber SecuritySazed Salman
 
My favourite season is spring
My favourite season is springMy favourite season is spring
My favourite season is springmane2004
 
April Showers Power Point
April Showers Power PointApril Showers Power Point
April Showers Power Pointmariamontroni
 
Getting Started with Spring Framework
Getting Started with Spring FrameworkGetting Started with Spring Framework
Getting Started with Spring FrameworkEdureka!
 
Spring season things
Spring season thingsSpring season things
Spring season thingsRana Maria Q
 
Compression Springs | Mechenical Engineering
Compression Springs | Mechenical EngineeringCompression Springs | Mechenical Engineering
Compression Springs | Mechenical EngineeringTransweb Global Inc
 
Spring, the sweet spring
Spring, the sweet springSpring, the sweet spring
Spring, the sweet springSimon Stevens
 

Viewers also liked (20)

Springs
SpringsSprings
Springs
 
Ppt springs
Ppt springsPpt springs
Ppt springs
 
Types of springs, its application and reasons
Types of springs, its application and reasonsTypes of springs, its application and reasons
Types of springs, its application and reasons
 
Springs & uses of springs
Springs & uses of springsSprings & uses of springs
Springs & uses of springs
 
Types of springs Design Machine Elements (DME)
Types of springs Design Machine Elements (DME)Types of springs Design Machine Elements (DME)
Types of springs Design Machine Elements (DME)
 
mechanical springs
mechanical springsmechanical springs
mechanical springs
 
Design of helical spring against static loading
Design of helical spring against static loadingDesign of helical spring against static loading
Design of helical spring against static loading
 
Springs-mechanical engineering
Springs-mechanical engineeringSprings-mechanical engineering
Springs-mechanical engineering
 
Design of Helical Spring
Design of Helical SpringDesign of Helical Spring
Design of Helical Spring
 
Design of mechanical spring
Design of mechanical springDesign of mechanical spring
Design of mechanical spring
 
Cyber Crime and Cyber Security
Cyber Crime and Cyber SecurityCyber Crime and Cyber Security
Cyber Crime and Cyber Security
 
My favourite season is spring
My favourite season is springMy favourite season is spring
My favourite season is spring
 
April Showers Power Point
April Showers Power PointApril Showers Power Point
April Showers Power Point
 
SPRING SEASON
SPRING SEASONSPRING SEASON
SPRING SEASON
 
Getting Started with Spring Framework
Getting Started with Spring FrameworkGetting Started with Spring Framework
Getting Started with Spring Framework
 
Spring & hibernate
Spring & hibernateSpring & hibernate
Spring & hibernate
 
Spring season things
Spring season thingsSpring season things
Spring season things
 
Compression Springs | Mechenical Engineering
Compression Springs | Mechenical EngineeringCompression Springs | Mechenical Engineering
Compression Springs | Mechenical Engineering
 
Seasons
SeasonsSeasons
Seasons
 
Spring, the sweet spring
Spring, the sweet springSpring, the sweet spring
Spring, the sweet spring
 

Similar to Spring ppt

Spring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggetsSpring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggetsVirtual Nuggets
 
Spring presentecion isil
Spring presentecion isilSpring presentecion isil
Spring presentecion isilWilly Aguirre
 
Spring presentecion isil
Spring presentecion isilSpring presentecion isil
Spring presentecion isilWilly Aguirre
 
How Spring Framework Really Works?
How Spring Framework Really Works?How Spring Framework Really Works?
How Spring Framework Really Works?NexSoftsys
 
TheSpringFramework
TheSpringFrameworkTheSpringFramework
TheSpringFrameworkShankar Nair
 
The Complete Spring Tutorial
The Complete Spring TutorialThe Complete Spring Tutorial
The Complete Spring Tutorialcribes
 
Framework adoption for java enterprise application development
Framework adoption for java enterprise application developmentFramework adoption for java enterprise application development
Framework adoption for java enterprise application developmentClarence Ho
 
Spring basics for freshers
Spring basics for freshersSpring basics for freshers
Spring basics for freshersSwati Bansal
 
Spring framework
Spring frameworkSpring framework
Spring frameworkKani Selvam
 
Introduction to j2 ee frameworks
Introduction to j2 ee frameworksIntroduction to j2 ee frameworks
Introduction to j2 ee frameworksMukesh Kumar
 
Project report for final year project
Project report for final year projectProject report for final year project
Project report for final year projectsuneel singh
 
Latest Web development technologies 2021
 Latest Web development technologies 2021 Latest Web development technologies 2021
Latest Web development technologies 2021SWATHYSMOHAN
 

Similar to Spring ppt (20)

Spring Framework Rohit
Spring Framework RohitSpring Framework Rohit
Spring Framework Rohit
 
Spring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggetsSpring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggets
 
Spring presentecion isil
Spring presentecion isilSpring presentecion isil
Spring presentecion isil
 
Spring presentecion isil
Spring presentecion isilSpring presentecion isil
Spring presentecion isil
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring
SpringSpring
Spring
 
Spring notes
Spring notesSpring notes
Spring notes
 
Spring
SpringSpring
Spring
 
How Spring Framework Really Works?
How Spring Framework Really Works?How Spring Framework Really Works?
How Spring Framework Really Works?
 
TheSpringFramework
TheSpringFrameworkTheSpringFramework
TheSpringFramework
 
The Complete Spring Tutorial
The Complete Spring TutorialThe Complete Spring Tutorial
The Complete Spring Tutorial
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Framework adoption for java enterprise application development
Framework adoption for java enterprise application developmentFramework adoption for java enterprise application development
Framework adoption for java enterprise application development
 
Spring basics for freshers
Spring basics for freshersSpring basics for freshers
Spring basics for freshers
 
spring
springspring
spring
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Introduction to j2 ee frameworks
Introduction to j2 ee frameworksIntroduction to j2 ee frameworks
Introduction to j2 ee frameworks
 
Spring
SpringSpring
Spring
 
Project report for final year project
Project report for final year projectProject report for final year project
Project report for final year project
 
Latest Web development technologies 2021
 Latest Web development technologies 2021 Latest Web development technologies 2021
Latest Web development technologies 2021
 

More from Mumbai Academisc

More from Mumbai Academisc (20)

Non ieee java projects list
Non  ieee java projects list Non  ieee java projects list
Non ieee java projects list
 
Non ieee dot net projects list
Non  ieee dot net projects list Non  ieee dot net projects list
Non ieee dot net projects list
 
Ieee java projects list
Ieee java projects list Ieee java projects list
Ieee java projects list
 
Ieee 2014 java projects list
Ieee 2014 java projects list Ieee 2014 java projects list
Ieee 2014 java projects list
 
Ieee 2014 dot net projects list
Ieee 2014 dot net projects list Ieee 2014 dot net projects list
Ieee 2014 dot net projects list
 
Ieee 2013 java projects list
Ieee 2013 java projects list Ieee 2013 java projects list
Ieee 2013 java projects list
 
Ieee 2013 dot net projects list
Ieee 2013 dot net projects listIeee 2013 dot net projects list
Ieee 2013 dot net projects list
 
Ieee 2012 dot net projects list
Ieee 2012 dot net projects listIeee 2012 dot net projects list
Ieee 2012 dot net projects list
 
Ejb notes
Ejb notesEjb notes
Ejb notes
 
Java web programming
Java web programmingJava web programming
Java web programming
 
Java programming-examples
Java programming-examplesJava programming-examples
Java programming-examples
 
Hibernate tutorial
Hibernate tutorialHibernate tutorial
Hibernate tutorial
 
J2ee project lists:-Mumbai Academics
J2ee project lists:-Mumbai AcademicsJ2ee project lists:-Mumbai Academics
J2ee project lists:-Mumbai Academics
 
Web based development
Web based developmentWeb based development
Web based development
 
Jdbc
JdbcJdbc
Jdbc
 
Java tutorial part 4
Java tutorial part 4Java tutorial part 4
Java tutorial part 4
 
Java tutorial part 3
Java tutorial part 3Java tutorial part 3
Java tutorial part 3
 
Java tutorial part 2
Java tutorial part 2Java tutorial part 2
Java tutorial part 2
 
Engineering
EngineeringEngineering
Engineering
 
Jsp
JspJsp
Jsp
 

Recently uploaded

MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...Krashi Coaching
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppCeline George
 
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatmentsaipooja36
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING IIII BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING IIagpharmacy11
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
The Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptxThe Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptxNehaChandwani11
 
How to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryHow to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryCeline George
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the lifeNitinDeodare
 
HVAC System | Audit of HVAC System | Audit and regulatory Comploance.pptx
HVAC System | Audit of HVAC System | Audit and regulatory Comploance.pptxHVAC System | Audit of HVAC System | Audit and regulatory Comploance.pptx
HVAC System | Audit of HVAC System | Audit and regulatory Comploance.pptxKunal10679
 
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Denish Jangid
 
Navigating the Misinformation Minefield: The Role of Higher Education in the ...
Navigating the Misinformation Minefield: The Role of Higher Education in the ...Navigating the Misinformation Minefield: The Role of Higher Education in the ...
Navigating the Misinformation Minefield: The Role of Higher Education in the ...Mark Carrigan
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45MysoreMuleSoftMeetup
 

Recently uploaded (20)

Word Stress rules esl .pptx
Word Stress rules esl               .pptxWord Stress rules esl               .pptx
Word Stress rules esl .pptx
 
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING IIII BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
The Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptxThe Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptx
 
How to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryHow to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 Inventory
 
IPL Online Quiz by Pragya; Question Set.
IPL Online Quiz by Pragya; Question Set.IPL Online Quiz by Pragya; Question Set.
IPL Online Quiz by Pragya; Question Set.
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the life
 
HVAC System | Audit of HVAC System | Audit and regulatory Comploance.pptx
HVAC System | Audit of HVAC System | Audit and regulatory Comploance.pptxHVAC System | Audit of HVAC System | Audit and regulatory Comploance.pptx
HVAC System | Audit of HVAC System | Audit and regulatory Comploance.pptx
 
“O BEIJO” EM ARTE .
“O BEIJO” EM ARTE                       .“O BEIJO” EM ARTE                       .
“O BEIJO” EM ARTE .
 
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
 
Navigating the Misinformation Minefield: The Role of Higher Education in the ...
Navigating the Misinformation Minefield: The Role of Higher Education in the ...Navigating the Misinformation Minefield: The Role of Higher Education in the ...
Navigating the Misinformation Minefield: The Role of Higher Education in the ...
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
 

Spring ppt

  • 1. Introduction to the Spring Framework By Mumbai Academics
  • 2. Advantages of Spring Framework Architecture There are many advantages of Spring Framework. They are as follows:  Lightweight: Spring framework is lightweight because of its POJO implementation. The Spring Framework doesn't force the programmer to inherit any class or implement any interface. That is why it is said non-invasive, Enable you to write powerful, scalable applications using POJOs.  Easy to develop JavaEE application: The Dependency Injection feature of Spring Framework and it support to various frameworks makes the easy development of JavaEE application.  Easy to test: The Dependency Injection makes easier to test the application. The EJB or Struts application require server to run the application but Spring framework doesn't require server.
  • 3.      Loose Coupling: The Spring applications are loosely coupled because of dependency injection and handles injecting dependent components without a component knowing where they came from (IoC). Powerful abstraction: It provides powerful abstraction to JavaEE specifications such as JMS, JDBC, JPA and JTA. Declarative support: It provides declarative support for caching, validation, transactions and formatting. Portable :can use server-side in web/ejb app, client-side in swing app, business logic is completely portable. Cross-cutting behavior : Resource Management is crosscutting concern, easy to copy-and-paste everywhere.
  • 4.   Configuration information: Spring provides one consistent way of configuring everything, separate configuration from application logic, varying configuration. Lifecycle : Responsible for managing all your application components, particularly those in the middle tier container sees components through well-defined lifecycle: init(), destroy()
  • 5. Spring  A popular and stable Java application framework for enterprise development     Ubiquitous for Java development Well established in enterprise Java apps Time tested and proven reliable A primary purpose is to reduce dependencies and even introduce negative dependencies  Different from almost every other framework out there  Part of the reason it has been adopted so quickly  Spring code base is proven to be well structured (possibly the best)  139 packages  No dependency cycles
  • 6. Spring  A lightweight framework that addresses each tier in a Web application.    Presentation layer – An MVC framework that is most similar to Struts but is more powerful and easy to use. Business layer – Lightweight IoC container and AOP support (including built in aspects) Persistence layer – DAO template support for popular ORMs and JDBC       Simplifies persistence frameworks and JDBC Complimentary: Not a replacement for a persistence framework Helps organize your middle tier and handle typical J2EE plumbing problems. Solutions to typical coding busywork  JDBC ,LDAP,Web Services Reduces code and speeds up development Current Version is 3.0
  • 7. Spring (continued)          Do I have to use all components of Spring? Spring is a non-invasive and portable framework that allows you to introduce as much or as little as you want to your application. Promotes decoupling and reusability POJO Based Allows developers to focus more on reused business logic and less on plumbing problems. Reduces or alleviates code littering, ad hoc singletons, factories, service locators and multiple configuration files. Removes common code issues like leaking connections and more. Built in aspects such as transaction management Most business objects in Spring apps do not depend on the Spring framework.
  • 8. Why Did I choose Spring?         Introduced to Spring by way of Hibernate Spring is an open source layered Java/J2EE application framework The Spring Framework is licensed under the terms of the Apache License Originally wanted Spring to provide a way to simplify DAO objects and provide declarative transaction support to our non-EJB applications. Needed a solution to loosely couple business logic in a POJO fashion. Wanted to build portable applications that provided clearer separation of presentation, business, and persistence logic. Easily integrated with our existing frameworks Great documentation and community support
  • 9. Spring Mission Statement          J2EE should be easier to use It's best to program to interfaces, rather than classes. Spring reduces the complexity cost of using interfaces to zero. JavaBeans offer a great way of configuring applications OO design is more important than any implementation technology, such as J2EE Checked exceptions are overused in Java. A framework shouldn't force you to catch exceptions you're unlikely to be able to recover from. Testability is essential, and a framework such as Spring should help make your code easier to test Spring should be a pleasure to use Your application code should not depend on Spring APIs Spring should not compete with good existing solutions, but should foster integration. (For example, JDO and Hibernate are great O/R mapping solutions. Don't need to develop another one).
  • 10. Simplify your code with Spring   Enables you to stop polluting code No more custom singleton objects       Beans are defined in a centralized configuration file No more custom factory object to build and/or locate other objects DAO simplification  Consistent CRUD  Data access templates  No more copy-paste try/catch/finally blocks  No more passing Connection objects between methods  No more leaked connections POJO Based Refactoring experience with Spring Caution Spring is addictive!
  • 11. Modules of the Spring Framework       The Spring Framework can be considered as a collection of frameworks-in-the-framework: Core - Inversion of Control (IoC) and Dependency Injection. AOP :- These modules support aspect oriented programming implementation where you can use Advices, Pointcuts etc. to decouple the code. DAO - Data Access Object support, transaction management, JDBC-abstraction ORM - Object Relational Mapping data access, integration layers for JPA, JDO, Hibernate, and iBatis MVC - Model-View-Controller implementation for webapplications Context-This module supports internationalization (I18N), EJB,Remote Access, Authentication and Authorization, Remote Management like RMI,HTTP Invoker,Hessain, Messaging Framework, Web Services, Email, Testing, …
  • 12. Modules of the Spring Framework  Expression Language:- It is an extension to the EL defined in JSP. It provides support to setting and getting property values, method invocation, accessing collections and indexers, named variables, logical and arithmetic operators, retrieval of objects by name etc.
  • 13. Overview of the Spring Framework Very loosely coupled, components widely reusable and separately packaged.
  • 14. Spring Details    Spring allows to decouple software layers by injecting a component’s dependencies at runtime rather than having them declared at compile time via importing and instantiating classes. Spring provides integration for J2EE services such as EJB, JDBC, JNDI, JMS, JTA. It also integrates several popular ORM toolkits such as Hibernate and JDO and assorted other services as well. One of the highly touted features is declarative transactions, which allows the developer to write transaction-unaware code and configure transactions in Spring config files.
  • 15. Spring Details   Spring is built on the principle of unchecked exception handling. This also reduces code dependencies between layers. Spring provides a granular exception hierarchy for data access operations and maps JDBC, EJB, and ORM exceptions to Spring exceptions so that applications can get better information about the error condition. With highly decoupled software layers and programming to interfaces, each layer is easier to test. Mock objects is a testing pattern that is very useful in this regard.
  • 16. Spring Solutions • Solutions address major J2EE problem areas: • • • • • • • Web application development (MVC) Enterprise Java Beans (EJB, JNDI) Database access (JDBC, iBatis, ORM) Transaction management (JTA, Hibernate, JDBC) Remote access (Web Services, RMI) Each solution builds on the core architecture Solutions foster integration, they do not re-invent the wheel
  • 17. How to Start Using Spring      create the class create the xml file to provide the values create the test class Load the spring jar files Run the test class
  • 21. Load the jar files required for spring framework There are mainly three jar files required to run this application.  org.springframework.core-3.0.1.RELEASE-A  com.springsource.org.apache.commons.logging-1.1.1  org.springframework.beans-3.0.1.RELEASE-A
  • 22. What are Lightweight Frameworks? • • • Non-intrusive No container requirements Simplify application development Remove re-occurring pattern code • Productivity friendly • Unit test friendly • • • • Very pluggable Usually open source Examples: • • • • • Spring, Pico, Hivemind Hibernate, IBatis, Castor WebWork Quartz Sitemesh
  • 23. Spring IoC + AOP  IoC container      Setter based and constructor based dependency injection Portable across application servers Promotes good use of OO practices such as programming to interfaces. Beans managed by an IoC container are reusable and decoupled from business logic AOP      Spring uses Dynamic AOP Proxy objects to provide crosscutting services Reusable components Aopalliance support today Integrates with the IoC container AspectJ support in Spring 1.1
  • 25. Inversion of Control        Dependency injection  Beans define their dependencies through constructor arguments or properties  The container provides the injection at runtime Decouples object creators and locators from application logic Easy to maintain and reuse Testing is easier Useful for separating dao and business layer Useful for separating controllers and business layer The code is more extensible, easier to read, and modules/layers can easily be replaced
  • 26. Non-IoC / Dependency Injection
  • 27. Non-IoC Service Object public class OrderServiceImpl implements IOrderService { public Order saveOrder(Order order) throws OrderException{ try{ // 1. Create a Session/Connection object // 2. Start a transaction // 3. Lookup and invoke one of the methods in a // DAO and pass the Session/Connection object. // 4. Commit transaction }catch(Exception e){ // handle e, rollback transaction, //cleanup, // throw e }finally{ //Release resources and handle more exceptions } }
  • 28. IoC / Dependency Injection
  • 29. IoC Service Object public class OrderSpringService implements IOrderService { IOrderDAO orderDAO; public Order saveOrder(Order order) throws OrderException{ // perform some business logic… return orderDAO.saveNewOrder(order); } public void setOrderDAO(IOrderDAO orderDAO) { this.orderDAO = orderDAO; }  Program to interfaces for your bean dependencies!
  • 30. Spring Bean Definition Typical java bean with a unique id  In spring there are basically two types   Singleton  One instance of the bean created and referenced each time it is requested  Prototype (non-singleton) New bean created each time  Same as new ClassName()   Beans are normally created by Spring as late as possible
  • 31. Spring Bean Definition     The bean class is the actual implementation of the bean being described by the BeanFactory. Bean examples – DAO, DataSource, Transaction Manager, Persistence Managers, Service objects, etc Spring config contains implementation classes while your code should program to interfaces. Bean behaviors include:  Singleton or prototype  Autowiring  Initialization and destruction methods    init-method destroy-method Beans can be configured to have property values set.  Can read simple values, collections, maps, references to other beans, etc.
  • 32. What is a bean definition?  Defines a bean for Spring to manage  Key        attributes class (required): fully qualified java class name id: the unique identifier for this bean configuration: (singleton, init-method, etc.) constructor-arg: arguments to pass to the constructor at creation time property: arguments to pass to the bean setters at creation time Collaborators: other beans needed in this bean (a.k.a dependencies), specified in property or constructor-arg Typically defined in an XML file
  • 33. Simple Spring Bean Example  <bean id=“orderBean” class=“example.OrderBean” init-method=“init”> <property name=“minimumAmountToProcess”>10</property> <property name=“orderDAO”> <ref bean=“orderDAOBean”/> </property> </bean>  public class OrderBean implements IOrderBean{ … public void setMinimumAmountToProcess(double d){ this. minimumAmountToProcess = d; } public void setOrderDAO(IOrderDAO odao){ this.orderDAO = odao; } }
  • 34. Spring BeanFactory  BeanFactory is core to the Spring framework        Lightweight container that loads bean definitions and manages your beans. Configured declaratively using an XML file, or files, that determine how beans can be referenced and wired together. Knows how to serve and manage a singleton or prototype defined bean Responsible for lifecycle methods. Injects dependencies into defined beans when served Avoids the use of singletons and factories Spring uses a BeanFactory to create, manage and locate “beans” which are basically instances of a class  Typical usage is an XML bean factory which allows configuration via XML files
  • 35. Spring ApplicationContext   A Spring ApplicationContext allows you to get access to the objects that are configured in a BeanFactory in a framework manner. ApplicationContext extends BeanFactory    Several ways to configure a context:     Adds services such as international messaging capabilities. Add the ability to load file resources in a generic fashion. XMLWebApplicationContext – Configuration for a web application. ClassPathXMLApplicationContext – standalone XML application context FileSystemXmlApplicationContext Allows you to avoid writing Service Locators
  • 39. Spring AOP     Framework that builds on the aopalliance interfaces. Aspects are coded with pure Java code. You do not need to learn pointcut query languages that are available in other AOP implementations. Separates the core business code from the aspects we wrap around it: security, transaction management, monitering,logging… Spring aspects can be configured using its own IoC container.    Objects obtained from the IoC container can be transparently advised based on configuration Spring AOP has built in aspects such as providing transaction management, performance monitoring and more for your beans Spring AOP is not as robust as some other implementations such as AspectJ.  However, it does support common aspect uses to solve
  • 40. Spring AOP  Attempts to separate concerns, increase modularity, and decrease redundancy  Separation  Break up features to minimize overlap  Don’t  of Concerns (SoC) Repeat Yourself (DRY) Minimize code duplication  Cross-Cutting   Concerns Program aspects that affect many others (e.g. logging) AspectJ is the top AOP package
  • 41. Spring AOP  Supports the following advices:           method before method after returning throws advice around advice (uses AOPAlliance MethodInterceptor directly) Spring allows you to chain together interceptors and advice with precedence. Aspects are weaved together at runtime. AspectJ uses compile time weaving. Spring AOP also includes advisors that contain advice and pointcut filtering. ProxyFactoryBean – sources AOP proxies from a Spring BeanFactory IoC + AOP is a great combination that is non-invasive Through AOP, we add transversal functionalities to objects (ie not directly related to the code it contains)
  • 42. 2. Spring principles: AOP  Without AOP  With AOP
  • 43. 2. Spring principles: AOP Useful for automatic handling of transaction with Hibernate  Useful for Acegi (automatic credentials checking before executing some methods)  Code smaller, easier to read (not polluted by transversal aspects not directly relevant) 
  • 45. Consistent Abstract Classes for DAO Support   Extend your DAO classes with the proper xxxDAOSupport class that matches your persistence mechanism. JdbcDaoSupport Super class for JDBC data access objects.  Requires a DataSource to be set, providing a JdbcTemplate based on it to subclasses.   HibernateDaoSupport Super class for Hibernate data access objects.  Requires a SessionFactory to be set, providing a HibernateTemplate based on it to subclasses.   JdoDaoSupport Super class for JDO data access objects.  Requires a PersistenceManagerFactory to be set, providing a JdoTemplate based on it to subclasses.   SqlMapDaoSupport Supper class for iBATIS SqlMap data access object.  Requires a DataSource to be set, providing a SqlMapTemplate 
  • 46. Spring DAO Templates        Built in code templates that support JDBC, Hibernate, JDO, and iBatis SQL Maps Simplifies data access coding by reducing redundant code and helps avoid common errors. Alleviates opening and closing connections in your DAO code. No more ThreadLocal or passing Connection/Session objects. Transaction management is handled by a wired bean You are dropped into the template with the resources you need for data access – Session, PreparedStatement, etc. Code only needs to be implemented in callback methods.   doInXXX(Object) Optional separate JDBC framework
  • 47. Ex: Code without a template public class OrderHibernateDAO implements IOrderDAO { public Order saveOrder(Order order) throws OrderException{ Session s = null; Transaction tx = null; try{ s = ... // get a new Session object tx = s.beginTransaction(); s.save(order); tx.commit(); } catch (HibernateException he){ // log, rollback, and convert to OrderException } catch (SQLException sqle){ // log, rollback, and convert to OrderException } finally { s.close(); // needs a try/catch block } return order; }
  • 48. Ex: Spring DAO Template Example public class OrderHibernateDAO extends HibernateDaoSupport implements IOrderDAO { ... public Order saveOrder(final Order order) { return (Order) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { session.save(order); return order; } }); } ... }
  • 49. Consistent Exception Handling  Spring has it’s own exception handling hierarchy for DAO logic.  No more copy and pasting redundant exception logic!  Exceptions from JDBC, or a supported ORM, are wrapped up into an appropriate, and consistent, DataAccessException and thrown.  This allows you to decouple exceptions in your business logic.  These exceptions are treated as unchecked exceptions that you can handle in your business tier if needed. No need to try/catch in your DAO.  Define your own exception translation by subclassing classes such as SQLErrorCodeSQLExceptionTranslator
  • 50. Spring and Testing Easier test driven development (TDD)  Integration testing   Can use a standalone Spring configuration with mock objects for testing.  Consider XMLApplicationContext or FileSystemApplicationContext.  Unit testing  Allows you to test outside the container without using the Spring container.  Easy to test POJOs
  • 52. MVC Framework       Clear separation of roles: controller, validator, form object, Dispatch servlet, View resolver, … Extensible and adaptable Several views of a result (pdf, excel, html, …) Can be wired (possible to use transparently the IoC pattern). Spring Annotation Based Controllers Spring 2.5 introduced support for annotation based MVC controllers. @RequestMapping, @RequestParam, @ModelAttribute are some of the annotations provided for this implementation.
  • 53.   Can be used with other frameworks: JSF, Struts, Tapestry, Webwork Completely transparent: no need to change anything in what is done by these other frameworks
  • 54. Benefits of the Spring Web MVC Framework The Spring Web MVC Framework is a robust, flexible, and well-designed framework for rapidly developing web applications using the MVC design pattern.The benefits achieved from using this Spring module are similar to those you get from the rest of the Spring Framework Easier testing—This is a common theme you will find across all the Spring classes.The fact that most of Spring’s classes are designed as JavaBeans enables you to inject test data using the setter methods of these classes. Spring also provides mock classes to simulate Java HTTP objects (HttpServletRequest, for example), which makes unit testing of the web layer much simpler.
  • 55. Benefits of the Spring Web MVC Framework Bind directly to business objects—Spring MVC does not require your business (model) classes to extend any special classes; this enables you to reuse your business objects by binding them directly to the HTML forms fields. In fact, your controller classes are the only ones that are required to extend Spring classes (or implement a Spring controller interface). Clear separation of roles—Spring MVC nicely separates the roles played by the various components that make up this web framework. For example, when we dis-cuss concepts such as controllers, command objects, and validators, you will begin to see how each component plays a distinct role.
  • 56. Benefits of the Spring Web MVC Framework Simple but powerful tag library—Spring's tag library is small, straightforward, but powerful. For example. Spring uses the JSP expression language (EL) for arguments to the <spring :bind> tag. Web Flow—This module is a subproject and is not bundled with the Spring core distribution. It is built on top of Spring MVC and adds the capability to easily write wizard like web applications that span across several HTTP requests (an online shopping cart, for example).
  • 57. Benefits of the Spring Web MVC Framework View technologies and web frameworks—Although we are using JSP as our view technology. Spring supports odier view technologies as well, such as Apache Velocity and FreeMarker.This is a powerful concept because switching from JSP to Velocity is a matter of configuration. Furthermore, Spring provides integration support for Apache Struts. ■ Lighter-weight environment—As I mentioned in die previous chapter. Spring enables you to build enterpriseready applications using FOJOs; the environment setup can be simpler and less expensive because you could develop and deploy your application using a lighterweight servlet container.
  • 58. Features of Spring Web MVC Spring's web module provides a wealth of unique web support features, including:  Clear separation of roles - controller, validator, command object, form object, model object, DispatcherServlet, handler mapping, view resolver, etc. Each role can be fulfilled by a specialized object.  Powerful and straightforward configuration of both framework and application classes as JavaBeans, including easy referencing across contexts, such as from web controllers to business objects and validators.  Adaptability, non-intrusiveness. Use whatever controller subclass you need (plain, command, form, wizard, multi-action, or a custom one) for a given scenario instead of deriving from a single controller for everything.  Reusable business code - no need for duplication. You can use existing business objects as command or form objects instead of mirroring them in order to extend a particular framework base
  • 59. Features of Spring Web MVC Customizable locale and theme resolution, support for JSPs with or without Spring tag library, support for JSTL, support for Velocity without the need for extra bridges, etc.  A simple yet powerful JSP tag library known as the Spring tag library that provides support for features such as data binding and themes. The custom tags allow for maximum flexibility in terms of markup code. For information on the tag library descriptor.  A JSP form tag library, introduced in Spring 2.0, that makes writing forms in JSP pages much easier. For information on the tag library descriptor.  Beans whose lifecycle is scoped to the current HTTP request or HTTP Session. This is not a specific feature of Spring MVC itself, but rather of the WebApplicationContext container(s) that Spring MVC uses. These bean scopes are described in detail in the section entitled.
  • 60. Features of Spring Web MVC Customizable binding and validation - type mismatches as application-level validation errors that keep the offending value, localized date and number binding, etc instead of String-only form objects with manual parsing and conversion to business objects.  Customizable handler mapping and view resolution - handler mapping and view resolution strategies range from simple URLbased configuration, to sophisticated, purpose-built resolution strategies. This is more flexible than some web MVC frameworks which mandate a particular technique.  Flexible model transfer - model transfer via a name/value Map supports easy integration with any view technology. 
  • 61. 4. A full MVC Framework
  • 62. Working Of MVC Framework    The Spring web MVC framework provides model-viewcontroller architecture and ready components that can be used to develop flexible and loosely coupled web applications. The MVC pattern results in separating the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements. The Model encapsulates the application data and in general they will consist of POJO. The View is responsible for rendering the model data and in general it generates HTML output that the client's browser can interpret. The Controller is responsible for processing user requests and building appropriate model and passes it to the view for rendering.
  • 63. The DispatcherServlet The Spring Web model-view-controller (MVC) framework is designed around a DispatcherServlet that handles all the HTTP requests and responses. The request processing workflow of the Spring Web MVC DispatcherServlet is illustrated in the following diagram:
  • 64.     Following is the sequence of events corresponding to an incoming HTTP request to DispatcherServlet: After receiving an HTTP request, DispatcherServlet consults the HandlerMapping to call the appropriate Controller. The Controller takes the request and calls the appropriate service methods based on used GET or POST method. The service method will set model data based on defined business logic and returns view name to the DispatcherServlet. The DispatcherServlet will take help from ViewResolver to pickup the defined view for the request. Once view is finalized, The DispatcherServlet passes the model data to the view which is finally rendered on the browser. All the above mentioned components ie. HandlerMapping, Controller and ViewResolver are parts ofWebApplicationContext which is an extension of the plain ApplicationContext with some extra features necessary for web applications.
  • 65. Even More Spring Components      JavaMail helpers Many ORM tools are supported: Hibernate, JDO, Apache OJB, iBATIS Templates using IoC to reduce the amount of code in the DAO objects Scheduling support via Quartz Convenience implementation classes for    Remoting support – JAXRPC, RMI, Hessian, and Burlap EJB support for easier access. Acegi Security System for Spring     http://acegisecurity.sourceforge.net/ Very good framework! Eclipse Plugin – Spring IDE for Eclipse Coming soon   JMS implementation classes JMX support

Editor's Notes

  1. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  2. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  3. Provides a good alternative to EJB for most applications Provides end-to-end framework for applications.
  4. Inversion of Control has already been referred to as Dependency Injection. The basic principle is that beans define their dependencies (i.e. the other objects they work with) only through constructor arguments or properties. Then, it is the job of the container to actually inject those dependencies when it creates the bean. This is fundamentally the inverse (hence the name Inversion of Control) of the bean instantiating or locating its dependencies on its own using direct construction of classes, or something like the Service Locator pattern. While we will not elaborate too much on the advantages of Dependency Injection, it becomes evident upon usage that code gets much cleaner and reaching a higher grade of decoupling is much easier when beans do not look up their dependencies, but are provided them, and additionally do not even know where the dependencies are located and of what actual type they are. As touched on in the previous paragraph, Inversion of Control/Dependency Injection exists in two major variants: setter-based dependency injection is realized by calling setters on your beans after invoking a no-argument constructor to instantiate your bean. Beans defined in the BeanFactory that use setter-based dependency injection are true JavaBeans. Spring generally advocates usage of setter-based dependency injection, since a large number of constructor arguments can get unwieldy, especially when some properties are optional. constructor-based dependency injection is realized by invoking a constructor with a number of arguments, each representing a collaborator or property. Although Spring generally advocates usage of setter-based dependency injection as much as possible, it does fully support the constructor-based approach as well, since you may wish to use it with pre-existing beans which provide only multi-argument constructors, and no setters. Additionally, for simpler beans, some people prefer the constructor approach as a means of ensuring beans can not be constructed in an invalid state.
  5. The DAO would be injected with a Session/Connection object
  6. For example WebSphere initializes Listeners after Servlets are loaded which is a bad thing in this case.