SlideShare a Scribd company logo
SKILLWISE – SPRING
FRAMEWORK
2
Contents
 What is Spring Framework?
 History of Spring Framework
 Spring Overview
 Spring Architecture
 IOC and Dependency Injection
 Bean Factory, Beans and Bean Definition
 Lifecycle events of a Bean
 Bean Post Processor
 Advantages of Spring
 Spring and EJB
3
What is Spring Framework?
 Spring is an open source framework
 Spring is a Lightweight Application framework
 Where Struts, WebWork and others can be considered
Web frameworks, Spring addresses all tiers of an
application
 Spring provides the plumbing so that you don’t have to
do the unwanted redundant job
 Essence of Spring is providing enterprise services to
simple POJO
4
History of Spring Framework
 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
 2004/2005 onwards: Spring is emerging as a leading
full-stack Java/J2EE application framework
 Recent version: 3.0
5
Spring Architecture - Overview
Note: Spring distribution comes as one big jar file and alternatively as a series of smaller jars
broken out along the above lines (so you can include only what you need)
6
Spring Architecture - Overview
 Spring Core: Most import component of the Spring Framework which provides the
Dependency Injection features. The BeanFactory provides a factory pattern which
separates the dependencies like initialization, creation and access of the objects from
the actual program logic
 Spring Context: Builds on the beans package to add support for message sources
and the ability for application objects to obtain resources using a consistent API
 Spring AOP: One of the key components of Spring. Used to provide declarative
enterprise services
 Spring ORM: Related to the database access using OR mapping
 Spring DAO: Used for standardizing the data access work using the technologies
like JDBC, Hibernate or JDO
 Spring Web: Spring’s web application development stack (includes Spring MVC)
 Spring Web MVC: Provides the MVC implementations for the web applications
7
But really, What is Spring?
 At it’s core, Spring provides:
• An Inversion of Control Container
o Also known as Dependency Injection
• An AOP Framework
o Spring provides a proxy-based AOP framework
• A Service Abstraction Layer
o Consistent integration with various standard and 3rd party APIs
 These together enables to write powerful, scalable
applications using POJOs
 Spring at it’s core is a framework for wiring up your
entire application
 Bean Factories are the heart of Spring
8
IOC and Dependency Injection
 Spring Container pushes dependency to the application
at runtime
 Against pull dependencies from environment
 Different types of injection
 Setter injection
<property name=“employeeDao”>
<ref local=“employeeDao”>
</property>
 Constructor injection
<constructor-arg>
<ref local=“employeeDao”>
<constructor-arg>
 Method injection
 How to decide between setter and constructor
injection?
Dependency Injection (IoC)
 The “Hollywood Principle”: Don’t call me, I’ll call you
 Eliminates lookup code from within your application
 Allows for pluggablity and hot swapping
 Promotes good OO design
 Enables reuse of existing code
 Makes your application extremely testable
10
Bean Factory
 A BeanFactory is typically configured in an XML file
with the root element: <beans>
 The XML contains one or more <bean> elements
 id (or name) attribute to identify the bean
 class attribute to specify the fully qualified class
 By default, beans are treated as singletons
 Can also be prototypes
<beans>
<bean id=“widgetService”
class=“com.zabada.base.WidgetService”>
<property name=“poolSize”>
<!—-property value here-->
</property>
</bean>
</beans>
The bean’s ID
The bean’s fully-
qualified
classname
Maps to a setPoolSize() call
Property Values for BeanFactories
 Strings and Numbers
 Arrays and Collections
<property name=“size”><value>42</value></property>
<property name=“name”><value>Jim</value></property>
<property name=“hobbies”>
<list>
<value>Basket Weaving</value>
<value>Break Dancing</value>
</list>
</property>
Property Values for BeanFactories (continued)
The real magic comes in when you can set a property on a
bean that refers to another bean in the configuration:
This is the basic concept of Inversion of Control
<bean name=“widgetService” class=“com.zabada.base.WidgetServiceImpl”>
<property name=“widgetDAO”>
<ref bean=“myWidgetDAO”/>
</property>
</bean>
calls
setWidgetDAO(myWidgetDAO)
where myWidgetDAO is another
bean defined in the configuration
A Very Special BeanFactory:
ApplicationContext
 An ApplicationContext is a BeanFactory with more
“framework” features such as:
– i18n messages
– Event notifications
 This is what you will probably use most often in your Spring
applications
14
Bean Factory and Configurations (Contd..,)
 Bean factory works as the container
 BeanFactory is an Interface
 ApplicationContext is also a beanfactory. It is a sub
class of BeanFactory interface
 How to start the container?
ApplicationContext context = new ClassPathApplicationContext(
new FileSystemXmlApplicationContext(
15
Bean information
 How to get the bean?
context.getBean(beanName)
 An individual bean definition contains the information
needed for the container to know how to create a bean, the
lifecycle methods and information about bean's
dependencies
 Usage of ref local and ref bean while accessing the
bean in multiple context files
16
Ref Local vs Ref Bean vs Ref Parent
 <ref local=“employeeDao” />
 <ref bean=“employeeDao” />
 <ref parent=“employeeDao” />
17
Spring Injection - Example
public class Inject {
private String name;
private int age;
private String company;
private String email;
private String address;
public void setAddress(String address) {
this.address = address;
}
public void setCompany(String company) {
this.company = company;
}
public void setEmail(String email) {
this.email = email;
}
public void setAge(int age) {
this.age = age;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return String.format("Name: %sn" +
"Age: %dn" +
"Address: %sn" +
"Company: %sn" +
"E-mail: %s",
this.name, this.age, this.address, this.company, this.email);
}
}
18
Spring Injection - Example
import org.springframework.beans.factory.xml.XmlBeanFactory
import org.springframework.core.io.ClassPathResource;
public class Main {
public static void main(String[] args) {
XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPath
Resource("context.xml"));
Inject demo = (Inject) beanFactory.getBean("mybean");
System.out.println(demo);
}
}
19
Spring Injection - Example
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="mybean"
class="Inject"
p:name=“Kumar"
p:age="28"
p:address=“Trivandrum"
p:company=“UST"
p:email=“kumar@ust-global.com"/>
</beans>
20
Spring Injection - Example
Name: Kumar
Age: 28
Address: Trivandrum
Company: UST
E-mail: kumar@ust-global.com
21
Other features of Bean configuration
 Auto wiring
 Automatically wires the beans
 Bean Post processor
 Special Listeners
 Post processing logic after a bean is initialized
Public interface BeanPostProcessor {
Object postProcessBeforeInitialization(Object bean, String beanName)
Object postProcessAfterInitialization(Object bean, String beanName)
}
 Property Place holder
 Place the property information in context.xml
22
Code Snippet for Bean Post Processor
public class DatabaseRow {
private String rowId;
private int noOfColumns;
private List<String> values;
public String getRowId() {
return rowId;
}
public void setRowId(String rowId) {
this.rowId = rowId;
}
public int getNoOfColumns() {
return noOfColumns;
}
public void setNoOfColumns(int noOfColumns) {
this.noOfColumns = noOfColumns;
}
public List<String> getValues() {
return values;
}
public void setValues(List<String> values) {
this.values = values;
}
}
23
Code Snippet for Bean Post Processor
public class DBRowBeanPostProcessor implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
throws BeansException {
System.out.println("Before Initialization");
System.out.println("Bean object: " + bean);
System.out.println("Bean name: " + beanName);
DatabaseRow dbRow = null;
if (bean instanceof DatabaseRow) {
dbRow = (DatabaseRow)bean;
dbRow.setRowId("ROWID-001");
dbRow.setNoOfColumns(3);
return dbRow;
}
return null;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
System.out.println("After Initialization");
System.out.println("Bean object: " + bean);
System.out.println("Bean name: " + beanName);
DatabaseRow dbRow = null;
if (bean instanceof DatabaseRow) {
dbRow = (DatabaseRow)bean;
dbRow.setValues(Arrays.asList("Antony", "10", "93232"));
return dbRow;
}
return null;
}
}
24
Code Snippet for Bean PreProcessor
static void beanPostProcessorTest()
{
Resource resource = new FileSystemResource("./src/resources/bean-lifecycle.xml");
ConfigurableBeanFactory xmlBeanFactory = new XmlBeanFactory(resource);
DBRowBeanPostProcessor processor = new DBRowBeanPostProcessor();
xmlBeanFactory.addBeanPostProcessor(processor);
DatabaseRow databaseRow =
(DatabaseRow)xmlBeanFactory.getBean("databaseRow");
System.out.println("Row Id: " + databaseRow.getRowId());
System.out.println("Columns: " + databaseRow.getNoOfColumns());
System.out.println("Values : " + databaseRow.getValues().toString());
}
25
How to initialize Spring in web.xml?
 Register the ContextLoader Servlet
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
 Specify the path of the Context configuration Location
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
26
Advantages of Spring Framework
 Non-invasive framework
 Promotes code reuse
 Facilitates Object Oriented programming
 Promotes pluggability
 Easy to test
 Spring provides a consistent way to glue your whole
application together
Quick Recap
 Open Source and Light weight application framework
 Bean Factory and Beans
 IOC or Dependency Injection
 Program to Interfaces
 Also, Spring comes with .Net flavour (Spring.net)
Spring and EJB
Discussion !!!
References
 Professional Java Development with Spring Framework –
Rod Johnson
 http://static.springsource.org
 http://www.springbyexample.org
30
Questions?
Skillwise-Spring framework 1
Ad

More Related Content

What's hot (20)

Spring Fa Qs
Spring Fa QsSpring Fa Qs
Spring Fa Qs
jbashask
 
Spring talk111204
Spring talk111204Spring talk111204
Spring talk111204
ealio
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
Hùng Nguyễn Huy
 
Build Amazing Add-ons for Atlassian JIRA and Confluence
Build Amazing Add-ons for Atlassian JIRA and ConfluenceBuild Amazing Add-ons for Atlassian JIRA and Confluence
Build Amazing Add-ons for Atlassian JIRA and Confluence
K15t
 
Integrating Plone with E-Commerce and Relationship Management: A Case Study i...
Integrating Plone with E-Commerce and Relationship Management: A Case Study i...Integrating Plone with E-Commerce and Relationship Management: A Case Study i...
Integrating Plone with E-Commerce and Relationship Management: A Case Study i...
David Glick
 
Using Rails to Create an Enterprise App: A Real-Life Case Study
Using Rails to Create an Enterprise App: A Real-Life Case StudyUsing Rails to Create an Enterprise App: A Real-Life Case Study
Using Rails to Create an Enterprise App: A Real-Life Case Study
David Keener
 
Spring boot jpa
Spring boot jpaSpring boot jpa
Spring boot jpa
Hamid Ghorbani
 
os-php-wiki5-a4
os-php-wiki5-a4os-php-wiki5-a4
os-php-wiki5-a4
tutorialsruby
 
Spring tutorial
Spring tutorialSpring tutorial
Spring tutorial
Sanjoy Kumer Deb
 
Spring MVC 5 & Hibernate 5 Integration
Spring MVC 5 & Hibernate 5 IntegrationSpring MVC 5 & Hibernate 5 Integration
Spring MVC 5 & Hibernate 5 Integration
Majurageerthan Arumugathasan
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
Hamid Ghorbani
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
Emprovise
 
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Arun Gupta
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with Spring
Joshua Long
 
Spring Framework -I
Spring Framework -ISpring Framework -I
Spring Framework -I
People Strategists
 
Spring talk111204
Spring talk111204Spring talk111204
Spring talk111204
s4al_com
 
Spring
SpringSpring
Spring
s4al_com
 
Reactjs Basics
Reactjs BasicsReactjs Basics
Reactjs Basics
Hamid Ghorbani
 
JEE Programming - 07 EJB Programming
JEE Programming - 07 EJB ProgrammingJEE Programming - 07 EJB Programming
JEE Programming - 07 EJB Programming
Danairat Thanabodithammachari
 
Servlets
ServletsServlets
Servlets
Abdalla Mahmoud
 
Spring Fa Qs
Spring Fa QsSpring Fa Qs
Spring Fa Qs
jbashask
 
Spring talk111204
Spring talk111204Spring talk111204
Spring talk111204
ealio
 
Build Amazing Add-ons for Atlassian JIRA and Confluence
Build Amazing Add-ons for Atlassian JIRA and ConfluenceBuild Amazing Add-ons for Atlassian JIRA and Confluence
Build Amazing Add-ons for Atlassian JIRA and Confluence
K15t
 
Integrating Plone with E-Commerce and Relationship Management: A Case Study i...
Integrating Plone with E-Commerce and Relationship Management: A Case Study i...Integrating Plone with E-Commerce and Relationship Management: A Case Study i...
Integrating Plone with E-Commerce and Relationship Management: A Case Study i...
David Glick
 
Using Rails to Create an Enterprise App: A Real-Life Case Study
Using Rails to Create an Enterprise App: A Real-Life Case StudyUsing Rails to Create an Enterprise App: A Real-Life Case Study
Using Rails to Create an Enterprise App: A Real-Life Case Study
David Keener
 
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Arun Gupta
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with Spring
Joshua Long
 
Spring talk111204
Spring talk111204Spring talk111204
Spring talk111204
s4al_com
 

Viewers also liked (17)

Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC
Naresh Chintalcheru
 
Skillwise Consulting New updated
Skillwise Consulting New updatedSkillwise Consulting New updated
Skillwise Consulting New updated
Skillwise Group
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
Tuna Tore
 
SpringMVC
SpringMVCSpringMVC
SpringMVC
Akio Katayama
 
Getting Started with Spring Framework
Getting Started with Spring FrameworkGetting Started with Spring Framework
Getting Started with Spring Framework
Edureka!
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
Santosh Kumar Kar
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Serhat Can
 
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
Edureka!
 
Spring boot
Spring bootSpring boot
Spring boot
sdeeg
 
Microservices Tracing With Spring Cloud and Zipkin @Szczecin JUG
Microservices Tracing With Spring Cloud and Zipkin @Szczecin JUGMicroservices Tracing With Spring Cloud and Zipkin @Szczecin JUG
Microservices Tracing With Spring Cloud and Zipkin @Szczecin JUG
Marcin Grzejszczak
 
Backday Xebia : Découvrez Spring Boot sur un cas pratique
Backday Xebia : Découvrez Spring Boot sur un cas pratiqueBackday Xebia : Découvrez Spring Boot sur un cas pratique
Backday Xebia : Découvrez Spring Boot sur un cas pratique
Publicis Sapient Engineering
 
ParisJUG Spring Boot
ParisJUG Spring BootParisJUG Spring Boot
ParisJUG Spring Boot
Julien Sadaoui
 
Workshop Spring - Session 4 - Spring Batch
Workshop Spring -  Session 4 - Spring BatchWorkshop Spring -  Session 4 - Spring Batch
Workshop Spring - Session 4 - Spring Batch
Antoine Rey
 
Workshop spring session 2 - La persistance au sein des applications Java
Workshop spring   session 2 - La persistance au sein des applications JavaWorkshop spring   session 2 - La persistance au sein des applications Java
Workshop spring session 2 - La persistance au sein des applications Java
Antoine Rey
 
Workshop Spring - Session 5 - Spring Integration
Workshop Spring - Session 5 - Spring IntegrationWorkshop Spring - Session 5 - Spring Integration
Workshop Spring - Session 5 - Spring Integration
Antoine Rey
 
Workshop Spring - Session 1 - L'offre Spring et les bases
Workshop Spring  - Session 1 - L'offre Spring et les basesWorkshop Spring  - Session 1 - L'offre Spring et les bases
Workshop Spring - Session 1 - L'offre Spring et les bases
Antoine Rey
 
Ces outils qui vous font gagner du temps
Ces outils qui vous font gagner du tempsCes outils qui vous font gagner du temps
Ces outils qui vous font gagner du temps
Antoine Rey
 
Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC
Naresh Chintalcheru
 
Skillwise Consulting New updated
Skillwise Consulting New updatedSkillwise Consulting New updated
Skillwise Consulting New updated
Skillwise Group
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
Tuna Tore
 
Getting Started with Spring Framework
Getting Started with Spring FrameworkGetting Started with Spring Framework
Getting Started with Spring Framework
Edureka!
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Serhat Can
 
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
Edureka!
 
Spring boot
Spring bootSpring boot
Spring boot
sdeeg
 
Microservices Tracing With Spring Cloud and Zipkin @Szczecin JUG
Microservices Tracing With Spring Cloud and Zipkin @Szczecin JUGMicroservices Tracing With Spring Cloud and Zipkin @Szczecin JUG
Microservices Tracing With Spring Cloud and Zipkin @Szczecin JUG
Marcin Grzejszczak
 
Backday Xebia : Découvrez Spring Boot sur un cas pratique
Backday Xebia : Découvrez Spring Boot sur un cas pratiqueBackday Xebia : Découvrez Spring Boot sur un cas pratique
Backday Xebia : Découvrez Spring Boot sur un cas pratique
Publicis Sapient Engineering
 
Workshop Spring - Session 4 - Spring Batch
Workshop Spring -  Session 4 - Spring BatchWorkshop Spring -  Session 4 - Spring Batch
Workshop Spring - Session 4 - Spring Batch
Antoine Rey
 
Workshop spring session 2 - La persistance au sein des applications Java
Workshop spring   session 2 - La persistance au sein des applications JavaWorkshop spring   session 2 - La persistance au sein des applications Java
Workshop spring session 2 - La persistance au sein des applications Java
Antoine Rey
 
Workshop Spring - Session 5 - Spring Integration
Workshop Spring - Session 5 - Spring IntegrationWorkshop Spring - Session 5 - Spring Integration
Workshop Spring - Session 5 - Spring Integration
Antoine Rey
 
Workshop Spring - Session 1 - L'offre Spring et les bases
Workshop Spring  - Session 1 - L'offre Spring et les basesWorkshop Spring  - Session 1 - L'offre Spring et les bases
Workshop Spring - Session 1 - L'offre Spring et les bases
Antoine Rey
 
Ces outils qui vous font gagner du temps
Ces outils qui vous font gagner du tempsCes outils qui vous font gagner du temps
Ces outils qui vous font gagner du temps
Antoine Rey
 
Ad

Similar to Skillwise-Spring framework 1 (20)

Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
Vinay Kumar
 
Toms introtospring mvc
Toms introtospring mvcToms introtospring mvc
Toms introtospring mvc
Guo Albert
 
2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf
DeoDuaNaoHet
 
Spring framework
Spring frameworkSpring framework
Spring framework
Rajkumar Singh
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Rajind Ruparathna
 
Spring framework
Spring frameworkSpring framework
Spring framework
Ajit Koti
 
Spring IOC and DAO
Spring IOC and DAOSpring IOC and DAO
Spring IOC and DAO
AnushaNaidu
 
Spring User Guide
Spring User GuideSpring User Guide
Spring User Guide
Muthuselvam RS
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
nomykk
 
Spring
SpringSpring
Spring
gauravashq
 
Spring
SpringSpring
Spring
gauravashq
 
Spring
SpringSpring
Spring
gauravashq
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Arjun Thakur
 
Spring (1)
Spring (1)Spring (1)
Spring (1)
Aneega
 
Spring training
Spring trainingSpring training
Spring training
shah_d_p
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
Dhaval Shah
 
SpringIntroductionpresentationoverintroduction.ppt
SpringIntroductionpresentationoverintroduction.pptSpringIntroductionpresentationoverintroduction.ppt
SpringIntroductionpresentationoverintroduction.ppt
imjdabhinawpandey
 
SpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptx
SUFYAN SATTAR
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Raveendra R
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Collaboration Technologies
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
Vinay Kumar
 
Toms introtospring mvc
Toms introtospring mvcToms introtospring mvc
Toms introtospring mvc
Guo Albert
 
2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf
DeoDuaNaoHet
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Rajind Ruparathna
 
Spring framework
Spring frameworkSpring framework
Spring framework
Ajit Koti
 
Spring IOC and DAO
Spring IOC and DAOSpring IOC and DAO
Spring IOC and DAO
AnushaNaidu
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
nomykk
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Arjun Thakur
 
Spring (1)
Spring (1)Spring (1)
Spring (1)
Aneega
 
Spring training
Spring trainingSpring training
Spring training
shah_d_p
 
SpringIntroductionpresentationoverintroduction.ppt
SpringIntroductionpresentationoverintroduction.pptSpringIntroductionpresentationoverintroduction.ppt
SpringIntroductionpresentationoverintroduction.ppt
imjdabhinawpandey
 
SpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptx
SUFYAN SATTAR
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Raveendra R
 
Ad

More from Skillwise Group (20)

Email Etiquette
Email Etiquette Email Etiquette
Email Etiquette
Skillwise Group
 
Healthcare profile
Healthcare profileHealthcare profile
Healthcare profile
Skillwise Group
 
Manufacturing courses
Manufacturing coursesManufacturing courses
Manufacturing courses
Skillwise Group
 
Retailing & logistics profile
Retailing & logistics profileRetailing & logistics profile
Retailing & logistics profile
Skillwise Group
 
Skillwise orientation
Skillwise orientationSkillwise orientation
Skillwise orientation
Skillwise Group
 
Overview- Skillwise Consulting
Overview- Skillwise Consulting Overview- Skillwise Consulting
Overview- Skillwise Consulting
Skillwise Group
 
Skillwise corporate presentation
Skillwise corporate presentationSkillwise corporate presentation
Skillwise corporate presentation
Skillwise Group
 
Skillwise Profile
Skillwise ProfileSkillwise Profile
Skillwise Profile
Skillwise Group
 
Skillwise Softskill Training Workshop
Skillwise Softskill Training WorkshopSkillwise Softskill Training Workshop
Skillwise Softskill Training Workshop
Skillwise Group
 
Skillwise Insurance profile
Skillwise Insurance profileSkillwise Insurance profile
Skillwise Insurance profile
Skillwise Group
 
Skillwise Train and Hire Services
Skillwise Train and Hire ServicesSkillwise Train and Hire Services
Skillwise Train and Hire Services
Skillwise Group
 
Skillwise Digital Technology
Skillwise Digital Technology Skillwise Digital Technology
Skillwise Digital Technology
Skillwise Group
 
Skillwise Boot Camp Training
Skillwise Boot Camp TrainingSkillwise Boot Camp Training
Skillwise Boot Camp Training
Skillwise Group
 
Skillwise Academy Profile
Skillwise Academy ProfileSkillwise Academy Profile
Skillwise Academy Profile
Skillwise Group
 
Skillwise Overview
Skillwise OverviewSkillwise Overview
Skillwise Overview
Skillwise Group
 
SKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPT
Skillwise Group
 
Skillwise - Business writing
Skillwise - Business writing Skillwise - Business writing
Skillwise - Business writing
Skillwise Group
 
Imc.ppt
Imc.pptImc.ppt
Imc.ppt
Skillwise Group
 
Skillwise cics part 1
Skillwise cics part 1Skillwise cics part 1
Skillwise cics part 1
Skillwise Group
 
Skillwise AML
Skillwise AMLSkillwise AML
Skillwise AML
Skillwise Group
 

Recently uploaded (20)

Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 

Skillwise-Spring framework 1

  • 2. 2 Contents  What is Spring Framework?  History of Spring Framework  Spring Overview  Spring Architecture  IOC and Dependency Injection  Bean Factory, Beans and Bean Definition  Lifecycle events of a Bean  Bean Post Processor  Advantages of Spring  Spring and EJB
  • 3. 3 What is Spring Framework?  Spring is an open source framework  Spring is a Lightweight Application framework  Where Struts, WebWork and others can be considered Web frameworks, Spring addresses all tiers of an application  Spring provides the plumbing so that you don’t have to do the unwanted redundant job  Essence of Spring is providing enterprise services to simple POJO
  • 4. 4 History of Spring Framework  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  2004/2005 onwards: Spring is emerging as a leading full-stack Java/J2EE application framework  Recent version: 3.0
  • 5. 5 Spring Architecture - Overview Note: Spring distribution comes as one big jar file and alternatively as a series of smaller jars broken out along the above lines (so you can include only what you need)
  • 6. 6 Spring Architecture - Overview  Spring Core: Most import component of the Spring Framework which provides the Dependency Injection features. The BeanFactory provides a factory pattern which separates the dependencies like initialization, creation and access of the objects from the actual program logic  Spring Context: Builds on the beans package to add support for message sources and the ability for application objects to obtain resources using a consistent API  Spring AOP: One of the key components of Spring. Used to provide declarative enterprise services  Spring ORM: Related to the database access using OR mapping  Spring DAO: Used for standardizing the data access work using the technologies like JDBC, Hibernate or JDO  Spring Web: Spring’s web application development stack (includes Spring MVC)  Spring Web MVC: Provides the MVC implementations for the web applications
  • 7. 7 But really, What is Spring?  At it’s core, Spring provides: • An Inversion of Control Container o Also known as Dependency Injection • An AOP Framework o Spring provides a proxy-based AOP framework • A Service Abstraction Layer o Consistent integration with various standard and 3rd party APIs  These together enables to write powerful, scalable applications using POJOs  Spring at it’s core is a framework for wiring up your entire application  Bean Factories are the heart of Spring
  • 8. 8 IOC and Dependency Injection  Spring Container pushes dependency to the application at runtime  Against pull dependencies from environment  Different types of injection  Setter injection <property name=“employeeDao”> <ref local=“employeeDao”> </property>  Constructor injection <constructor-arg> <ref local=“employeeDao”> <constructor-arg>  Method injection  How to decide between setter and constructor injection?
  • 9. Dependency Injection (IoC)  The “Hollywood Principle”: Don’t call me, I’ll call you  Eliminates lookup code from within your application  Allows for pluggablity and hot swapping  Promotes good OO design  Enables reuse of existing code  Makes your application extremely testable
  • 10. 10 Bean Factory  A BeanFactory is typically configured in an XML file with the root element: <beans>  The XML contains one or more <bean> elements  id (or name) attribute to identify the bean  class attribute to specify the fully qualified class  By default, beans are treated as singletons  Can also be prototypes <beans> <bean id=“widgetService” class=“com.zabada.base.WidgetService”> <property name=“poolSize”> <!—-property value here--> </property> </bean> </beans> The bean’s ID The bean’s fully- qualified classname Maps to a setPoolSize() call
  • 11. Property Values for BeanFactories  Strings and Numbers  Arrays and Collections <property name=“size”><value>42</value></property> <property name=“name”><value>Jim</value></property> <property name=“hobbies”> <list> <value>Basket Weaving</value> <value>Break Dancing</value> </list> </property>
  • 12. Property Values for BeanFactories (continued) The real magic comes in when you can set a property on a bean that refers to another bean in the configuration: This is the basic concept of Inversion of Control <bean name=“widgetService” class=“com.zabada.base.WidgetServiceImpl”> <property name=“widgetDAO”> <ref bean=“myWidgetDAO”/> </property> </bean> calls setWidgetDAO(myWidgetDAO) where myWidgetDAO is another bean defined in the configuration
  • 13. A Very Special BeanFactory: ApplicationContext  An ApplicationContext is a BeanFactory with more “framework” features such as: – i18n messages – Event notifications  This is what you will probably use most often in your Spring applications
  • 14. 14 Bean Factory and Configurations (Contd..,)  Bean factory works as the container  BeanFactory is an Interface  ApplicationContext is also a beanfactory. It is a sub class of BeanFactory interface  How to start the container? ApplicationContext context = new ClassPathApplicationContext( new FileSystemXmlApplicationContext(
  • 15. 15 Bean information  How to get the bean? context.getBean(beanName)  An individual bean definition contains the information needed for the container to know how to create a bean, the lifecycle methods and information about bean's dependencies  Usage of ref local and ref bean while accessing the bean in multiple context files
  • 16. 16 Ref Local vs Ref Bean vs Ref Parent  <ref local=“employeeDao” />  <ref bean=“employeeDao” />  <ref parent=“employeeDao” />
  • 17. 17 Spring Injection - Example public class Inject { private String name; private int age; private String company; private String email; private String address; public void setAddress(String address) { this.address = address; } public void setCompany(String company) { this.company = company; } public void setEmail(String email) { this.email = email; } public void setAge(int age) { this.age = age; } public void setName(String name) { this.name = name; } @Override public String toString() { return String.format("Name: %sn" + "Age: %dn" + "Address: %sn" + "Company: %sn" + "E-mail: %s", this.name, this.age, this.address, this.company, this.email); } }
  • 18. 18 Spring Injection - Example import org.springframework.beans.factory.xml.XmlBeanFactory import org.springframework.core.io.ClassPathResource; public class Main { public static void main(String[] args) { XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPath Resource("context.xml")); Inject demo = (Inject) beanFactory.getBean("mybean"); System.out.println(demo); } }
  • 19. 19 Spring Injection - Example <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="mybean" class="Inject" p:name=“Kumar" p:age="28" p:address=“Trivandrum" p:company=“UST" p:email=“[email protected]"/> </beans>
  • 20. 20 Spring Injection - Example Name: Kumar Age: 28 Address: Trivandrum Company: UST E-mail: [email protected]
  • 21. 21 Other features of Bean configuration  Auto wiring  Automatically wires the beans  Bean Post processor  Special Listeners  Post processing logic after a bean is initialized Public interface BeanPostProcessor { Object postProcessBeforeInitialization(Object bean, String beanName) Object postProcessAfterInitialization(Object bean, String beanName) }  Property Place holder  Place the property information in context.xml
  • 22. 22 Code Snippet for Bean Post Processor public class DatabaseRow { private String rowId; private int noOfColumns; private List<String> values; public String getRowId() { return rowId; } public void setRowId(String rowId) { this.rowId = rowId; } public int getNoOfColumns() { return noOfColumns; } public void setNoOfColumns(int noOfColumns) { this.noOfColumns = noOfColumns; } public List<String> getValues() { return values; } public void setValues(List<String> values) { this.values = values; } }
  • 23. 23 Code Snippet for Bean Post Processor public class DBRowBeanPostProcessor implements BeanPostProcessor { @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { System.out.println("Before Initialization"); System.out.println("Bean object: " + bean); System.out.println("Bean name: " + beanName); DatabaseRow dbRow = null; if (bean instanceof DatabaseRow) { dbRow = (DatabaseRow)bean; dbRow.setRowId("ROWID-001"); dbRow.setNoOfColumns(3); return dbRow; } return null; } @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { System.out.println("After Initialization"); System.out.println("Bean object: " + bean); System.out.println("Bean name: " + beanName); DatabaseRow dbRow = null; if (bean instanceof DatabaseRow) { dbRow = (DatabaseRow)bean; dbRow.setValues(Arrays.asList("Antony", "10", "93232")); return dbRow; } return null; } }
  • 24. 24 Code Snippet for Bean PreProcessor static void beanPostProcessorTest() { Resource resource = new FileSystemResource("./src/resources/bean-lifecycle.xml"); ConfigurableBeanFactory xmlBeanFactory = new XmlBeanFactory(resource); DBRowBeanPostProcessor processor = new DBRowBeanPostProcessor(); xmlBeanFactory.addBeanPostProcessor(processor); DatabaseRow databaseRow = (DatabaseRow)xmlBeanFactory.getBean("databaseRow"); System.out.println("Row Id: " + databaseRow.getRowId()); System.out.println("Columns: " + databaseRow.getNoOfColumns()); System.out.println("Values : " + databaseRow.getValues().toString()); }
  • 25. 25 How to initialize Spring in web.xml?  Register the ContextLoader Servlet <servlet> <servlet-name>context</servlet-name> <servlet-class> org.springframework.web.context.ContextLoaderServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet>  Specify the path of the Context configuration Location <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param>
  • 26. 26 Advantages of Spring Framework  Non-invasive framework  Promotes code reuse  Facilitates Object Oriented programming  Promotes pluggability  Easy to test  Spring provides a consistent way to glue your whole application together
  • 27. Quick Recap  Open Source and Light weight application framework  Bean Factory and Beans  IOC or Dependency Injection  Program to Interfaces  Also, Spring comes with .Net flavour (Spring.net)
  • 29. References  Professional Java Development with Spring Framework – Rod Johnson  http://static.springsource.org  http://www.springbyexample.org