SlideShare a Scribd company logo
SPRING
What is a framework?
 Framework is a collection of classes of predefined code to which
can use in your program to solve some problems.
 Advantages of java framework:
 Efficiency
 Security
 Expense
 Support
 Disadvantages of java framework:
 Restriction-we cannot modify the API
 Code is public-The framework is readily available to
everyone.
 Custom built feature
Difference between java framework and SPRING
 Spring framework-will increase the efficiency of the application and will
reduce overall application development time. So we can easily develop our
project within the given time framework.
What are advantages of SPRING framework?
 Powerful open source
 Light weight application framework.
 Reduces overall complexities.
 It is framework of frameworks.
 We can integrate hibernate code with spring code
SPRING was first released on February
2003 by Rod Johnson
Why spring is so popular?
 It is the distinct division between java beans models, controllers
and view.(Spring is basically an MVC architecture)
 Spring MVC is very flexible as it make use of interfaces.
*no restriction come over here.
*we can use our implementation as per our requirement.
 Spring is a:
Application framework.
Light weighted.
Layered architecture.
Loose coupling(less dependency of one module to another module)
Easy integration with ORM technologies(we can integrate hibernate)
What is the difference between spring and hibernate?
 Spring and Hibernate are two different things, Spring has several components
like Dependency Injection, Spring MVC, Spring ORM, Spring Rest API.
 So Spring ORM and Hibernate are kind of similar, they both deal with the
object relation model, which means they deal with connection java objects to
data base entities.
 Loose coupling-The dependent objects are written outside your java code so
if you need to change the dependent object you just need to change it in one
location(xml configuration file).
 Hibernate- It provides with ORM where in you are able to perform database
transaction is the form of objects mapped to corresponding table, using
configuration xml files.
 Spring, on the other hand is a framework that helps you follow the MVC
architecture in an effective and efficient way.
SPRING ARCHITECTURE
 The Spring framework is a layered architecture which consists of several
modules.
 All modules are built on the top of its core container.
 These modules provide everything that a developer may need for use in
the enterprise application development.
 He is always free to choose what features he needs and eliminate the
modules which are of no use.
 It's modular architecture enables integration with other frameworks.
Spring Architecture continues….
 The Core Module: Provides the Dependency Injection (DI) feature which is the
basic concept of the Spring framework. This module contains the BeanFactory, an
implementation of Factory Pattern which creates the bean as per the configurations
provided by the developer in an XML file. Core Container
Core: provides the fundamental parts of Spring framework.
Bean: It’s an object. Provides Bean Factory.
 BeanFactory, an implementation of Factory Pattern which creates the bean
as per the configurations provided by the developer in an XML file
Context: It's a medium to access any objects defined and configured.
SpEL-Spring Expression Language:it provides a powerful expression
language.
Data access
JDBC:provides a jdbc abstraction layer.
ORM:provides integration layers for popular object-relational
mapping API’s.
OXM: Object XML Mapping. Provides an abstraction layer.
JMS(Java Message Service):contains features for producing and
consuming messages.
Transactions:support programmatic and declarative transaction
management.
Web Module: Spring comes with MVC framework which eases
the task of developing web applications. It also integrates well with the
most popular MVC frameworks like Struts, JSF, etc.
Web Socket:provide support for web socket based a two way
communication between client and server.
Servlet:it is the core part of enterprise edition.Contains Spring
MVC implementation for web application.
Web:provide basic web-oriented integration features.
Portlet: provides MVC implementation. It is a stand alone
application.
Miscellaneous
AOP: provides an Aspect-Oriented Programming
implementation. It aims at declarative transaction management
which is easier to maintain.
Aspects: provides integration with aspects.
Instrumentation:provides class instrumentation support and
class loader implementations.
Messaging:provide support for messaging.
Test:support Support the testing of spring components(unit
testing)
Spring IoC Containers
 The Spring container is at the core of the Spring Framework.
 The container will create the objects, wire them together, configure them,
and manage their complete life cycle from creation till destruction.
 The Spring container uses DI(Dependency Injection) to manage the
components that make up an application. (Dependency injection-Just direct object
its dependent object and container will bind them at runtime)
 Dependency Injection (DI) is a design pattern that removes the
dependency from the programming code so that it can be easy to
manage and test the application. Dependency Injection makes our
programming code loosely coupled
 Spring provides the following two distinct types of containers.
Spring BeanFactory Container
This is the simplest container and is defined by
the org.springframework.beans.factory.BeanFactory interface.
Spring ApplicationContext Container
This container adds more enterprise-specific functionality.
This container is defined by
the org.springframework.context.ApplicationContext interface.
 The ApplicationContext container includes all functionality of
the BeanFactorycontainer, so it is generally recommended
over BeanFactory.
 BeanFactory can still be used for lightweight applications like mobile
devices or applet-based applications where data volume and speed is
significant.
BEAN SCOPE &METHOD INJECTION
 Spring Bean Definition: The objects that form the backbone of your
application and that are managed by the Spring IoC container are called beans.
 A bean is an object that is instantiated, assembled, and otherwise managed by a
Spring IoC container.
 When defining a <bean> you have the option of declaring a scope for that bean.
The Spring Framework supports the following five scopes
Singleton-Only one singleton instance will be created(default)
Prototype-Creates any number of instance from a single bean configuration.
Below three are connected with web based application Only valid in the
context of a web-aware Spring ApplicationContext
Request- This scopes a bean definition to an HTTP request.
Session-This scopes a bean definition to an HTTP session.
Global Session-This scopes a bean definition to a global HTTP session.
<bean name=“student” class=“Student” scope=“prototype”/>
Singleton Scope
 Default scope-if we don’t define anything in scope spring construct
automatically to Singleton Scope
 With this what does it mean that, even though you call an instance of the
bean using spring framework for one or more times all the time only one
instance will return.
Single student
instance
ctx.getBean(“student”)
Spring
Container
Prototype Scope
Spring
Container
Multiple
beans
For ‘n’ number of request using ctx.getBean(“student”) you get
‘n’ number of instance to the application that means every call you
get new instance of bean.
Method Injection-Method Replace
class MobileStore
{
public String buyMobile()
{
return “Bought a Mobile
Phone”;
}
}
class MobileStoreReplacer implements
MethodReplacer
{
public Object reimplement(Object
obj,Method method,Object[]args)
throws Throwable
{
return “Bought an iPhone”;
}
}
<bean id=“mobileStore” class “MobileStore”>
<replace-method name=“buyMobile”
replacer=“mobileStoreReplacer”/></bean>
<bean id=“mobileStoreReplacer” class
“MobileStoreReplacer”/>
On run time when ever you get a bean of mobile Store through
spring framework and call buyMobile.Spring understands it
need to replace buyMobile to MobileStoreReplacer.
Spring (1)
Spring (1)
Spring (1)
Spring - Bean Definition Inheritance
 A bean definition can contain a lot of configuration information, including
constructor arguments, property values and so on.
 Spring Bean definition inheritance has nothing to do with Java class
inheritance but the inheritance concept is same.
 Following is the configuration file Beans.xml where we defined "helloWorld"
bean which has two properties message1 and message2. Next "helloIndia"
bean has been defined as a child of "helloWorld" bean by using parent
attribute. The child bean inherits message2 property as is, and overrides
message1 property and introduces one more property message3.
Beans.xml
<?xml version = "1.0" encoding = "UTF-8"?>
<bean id = "helloWorld" class = "com.tutorialspoint.HelloWorld">
<property name = "message1" value = "Hello World!"/>
<property name = "message2" value = "Hello Second World!"/>
</bean>
<bean id ="helloIndia" class = "com.tutorialspoint.HelloIndia"
parent = "helloWorld">
<property name = "message1" value = "Hello India!"/>
<property name = "message3" value = "Namaste India!"/>
</bean> </beans>
HelloWorld.java
public class HelloWorld
{ private String message1;
private String message2;
public void setMessage1(String message)
{
this.message1 = message;
}
public void setMessage2(String message)
{
this.message2 = message;
}
public void getMessage1()
{ System.out.println("World Message1 : " + message1);
}
public void getMessage2()
{
System.out.println("World Message2 : " + message2);} }
HelloIndia.java
public class HelloIndia
{
private String message1;
private String message2;
private String message3;
public void setMessage1(String message)
{
this.message1 = message;
}
public void setMessage2(String message)
{
this.message2 = message;
}
public void setMessage3(String message)
{ this.message3 = message; } public void getMessage1(){ System.out.println
("India Message1 : " + message1);
} public void getMessage2(){ System.out.println("India Message2 : " + message2);
} public void getMessage3(){ System.out.println("India Message3 : " + message3); } }
MainApp.java
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MainApp
{ public static void main(String[] args)
{ ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
HelloWorld objA = (HelloWorld) context.getBean("helloWorld");
objA.getMessage1();
objA.getMessage2();
HelloIndia objB = (HelloIndia) context.getBean("helloIndia");
objB.getMessage1();
objB.getMessage2();
objB.getMessage3(); } }
output
World Message1 : Hello World!
World Message2 : Hello Second World!
India Message1 : Hello India!
India Message2 : Hello Second World!
India Message3 : Namaste India!
THANK YOU

More Related Content

PPTX
Hibernate ppt
PPTX
Hibernate tutorial
PPT
Hibernate presentation
PPTX
Hibernate in Action
DOC
Hibernate tutorial for beginners
PPTX
Hibernate
ODP
Hibernate Developer Reference
PPTX
Introduction to Hibernate Framework
Hibernate ppt
Hibernate tutorial
Hibernate presentation
Hibernate in Action
Hibernate tutorial for beginners
Hibernate
Hibernate Developer Reference
Introduction to Hibernate Framework

What's hot (20)

PDF
Hibernate 3
PPS
Java Hibernate Programming with Architecture Diagram and Example
PPT
Hibernate
PPT
Hibernate architecture
PPT
Introduction to Hibernate
PPT
Hibernate Tutorial
PPTX
Hibernate Basic Concepts - Presentation
PPTX
Hibernate in Nutshell
PPTX
Spring & hibernate
PDF
Introduction to JPA and Hibernate including examples
PPT
Java Persistence API (JPA) Step By Step
PPT
jpa-hibernate-presentation
PDF
Introduction To Hibernate
DOC
24 collections framework interview questions
PPT
hibernate with JPA
PDF
Hibernate Presentation
PDF
Hibernate Interview Questions
PDF
JPA and Hibernate
PDF
Hibernate An Introduction
PPTX
Introduction to JPA Framework
Hibernate 3
Java Hibernate Programming with Architecture Diagram and Example
Hibernate
Hibernate architecture
Introduction to Hibernate
Hibernate Tutorial
Hibernate Basic Concepts - Presentation
Hibernate in Nutshell
Spring & hibernate
Introduction to JPA and Hibernate including examples
Java Persistence API (JPA) Step By Step
jpa-hibernate-presentation
Introduction To Hibernate
24 collections framework interview questions
hibernate with JPA
Hibernate Presentation
Hibernate Interview Questions
JPA and Hibernate
Hibernate An Introduction
Introduction to JPA Framework
Ad

Similar to Spring (1) (20)

PPTX
Spring framework-tutorial
PPTX
Spring Basics
PPTX
Introduction to Spring Framework
 
PPTX
Introduction to Spring Framework
PDF
Spring 2
DOCX
Spring notes
ODP
Spring User Guide
PDF
Spring mvc
PPTX
Introduction to Spring sec1.pptx
PPTX
spring framework ppt by Rohit malav
PPTX
Java Spring Framework
PPTX
Spring framework Introduction
PPTX
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
DOCX
Spring Fa Qs
PPTX
PDF
Spring Framework Tutorial | VirtualNuggets
PPTX
Spring Framework
PPTX
Java spring ppt
PDF
Spring Framework
PPTX
Java J2EE Interview Questions Part 2
Spring framework-tutorial
Spring Basics
Introduction to Spring Framework
 
Introduction to Spring Framework
Spring 2
Spring notes
Spring User Guide
Spring mvc
Introduction to Spring sec1.pptx
spring framework ppt by Rohit malav
Java Spring Framework
Spring framework Introduction
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Spring Fa Qs
Spring Framework Tutorial | VirtualNuggets
Spring Framework
Java spring ppt
Spring Framework
Java J2EE Interview Questions Part 2
Ad

Recently uploaded (20)

PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Cell Types and Its function , kingdom of life
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
RMMM.pdf make it easy to upload and study
PPTX
Pharma ospi slides which help in ospi learning
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Business Ethics Teaching Materials for college
PDF
Complications of Minimal Access Surgery at WLH
PDF
01-Introduction-to-Information-Management.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPH.pptx obstetrics and gynecology in nursing
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
STATICS OF THE RIGID BODIES Hibbelers.pdf
VCE English Exam - Section C Student Revision Booklet
Cell Types and Its function , kingdom of life
human mycosis Human fungal infections are called human mycosis..pptx
RMMM.pdf make it easy to upload and study
Pharma ospi slides which help in ospi learning
Microbial disease of the cardiovascular and lymphatic systems
FourierSeries-QuestionsWithAnswers(Part-A).pdf
O7-L3 Supply Chain Operations - ICLT Program
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Pharmacology of Heart Failure /Pharmacotherapy of CHF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Business Ethics Teaching Materials for college
Complications of Minimal Access Surgery at WLH
01-Introduction-to-Information-Management.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf

Spring (1)

  • 2. What is a framework?  Framework is a collection of classes of predefined code to which can use in your program to solve some problems.  Advantages of java framework:  Efficiency  Security  Expense  Support
  • 3.  Disadvantages of java framework:  Restriction-we cannot modify the API  Code is public-The framework is readily available to everyone.  Custom built feature
  • 4. Difference between java framework and SPRING  Spring framework-will increase the efficiency of the application and will reduce overall application development time. So we can easily develop our project within the given time framework. What are advantages of SPRING framework?  Powerful open source  Light weight application framework.  Reduces overall complexities.  It is framework of frameworks.  We can integrate hibernate code with spring code
  • 5. SPRING was first released on February 2003 by Rod Johnson Why spring is so popular?  It is the distinct division between java beans models, controllers and view.(Spring is basically an MVC architecture)  Spring MVC is very flexible as it make use of interfaces. *no restriction come over here. *we can use our implementation as per our requirement.
  • 6.  Spring is a: Application framework. Light weighted. Layered architecture. Loose coupling(less dependency of one module to another module) Easy integration with ORM technologies(we can integrate hibernate)
  • 7. What is the difference between spring and hibernate?  Spring and Hibernate are two different things, Spring has several components like Dependency Injection, Spring MVC, Spring ORM, Spring Rest API.  So Spring ORM and Hibernate are kind of similar, they both deal with the object relation model, which means they deal with connection java objects to data base entities.  Loose coupling-The dependent objects are written outside your java code so if you need to change the dependent object you just need to change it in one location(xml configuration file).  Hibernate- It provides with ORM where in you are able to perform database transaction is the form of objects mapped to corresponding table, using configuration xml files.  Spring, on the other hand is a framework that helps you follow the MVC architecture in an effective and efficient way.
  • 9.  The Spring framework is a layered architecture which consists of several modules.  All modules are built on the top of its core container.  These modules provide everything that a developer may need for use in the enterprise application development.  He is always free to choose what features he needs and eliminate the modules which are of no use.  It's modular architecture enables integration with other frameworks.
  • 10. Spring Architecture continues….  The Core Module: Provides the Dependency Injection (DI) feature which is the basic concept of the Spring framework. This module contains the BeanFactory, an implementation of Factory Pattern which creates the bean as per the configurations provided by the developer in an XML file. Core Container Core: provides the fundamental parts of Spring framework. Bean: It’s an object. Provides Bean Factory.  BeanFactory, an implementation of Factory Pattern which creates the bean as per the configurations provided by the developer in an XML file Context: It's a medium to access any objects defined and configured. SpEL-Spring Expression Language:it provides a powerful expression language.
  • 11. Data access JDBC:provides a jdbc abstraction layer. ORM:provides integration layers for popular object-relational mapping API’s. OXM: Object XML Mapping. Provides an abstraction layer. JMS(Java Message Service):contains features for producing and consuming messages. Transactions:support programmatic and declarative transaction management.
  • 12. Web Module: Spring comes with MVC framework which eases the task of developing web applications. It also integrates well with the most popular MVC frameworks like Struts, JSF, etc. Web Socket:provide support for web socket based a two way communication between client and server. Servlet:it is the core part of enterprise edition.Contains Spring MVC implementation for web application. Web:provide basic web-oriented integration features. Portlet: provides MVC implementation. It is a stand alone application.
  • 13. Miscellaneous AOP: provides an Aspect-Oriented Programming implementation. It aims at declarative transaction management which is easier to maintain. Aspects: provides integration with aspects. Instrumentation:provides class instrumentation support and class loader implementations. Messaging:provide support for messaging. Test:support Support the testing of spring components(unit testing)
  • 14. Spring IoC Containers  The Spring container is at the core of the Spring Framework.  The container will create the objects, wire them together, configure them, and manage their complete life cycle from creation till destruction.  The Spring container uses DI(Dependency Injection) to manage the components that make up an application. (Dependency injection-Just direct object its dependent object and container will bind them at runtime)  Dependency Injection (DI) is a design pattern that removes the dependency from the programming code so that it can be easy to manage and test the application. Dependency Injection makes our programming code loosely coupled
  • 15.  Spring provides the following two distinct types of containers. Spring BeanFactory Container This is the simplest container and is defined by the org.springframework.beans.factory.BeanFactory interface. Spring ApplicationContext Container This container adds more enterprise-specific functionality. This container is defined by the org.springframework.context.ApplicationContext interface.
  • 16.  The ApplicationContext container includes all functionality of the BeanFactorycontainer, so it is generally recommended over BeanFactory.  BeanFactory can still be used for lightweight applications like mobile devices or applet-based applications where data volume and speed is significant.
  • 17. BEAN SCOPE &METHOD INJECTION  Spring Bean Definition: The objects that form the backbone of your application and that are managed by the Spring IoC container are called beans.  A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container.  When defining a <bean> you have the option of declaring a scope for that bean.
  • 18. The Spring Framework supports the following five scopes Singleton-Only one singleton instance will be created(default) Prototype-Creates any number of instance from a single bean configuration. Below three are connected with web based application Only valid in the context of a web-aware Spring ApplicationContext Request- This scopes a bean definition to an HTTP request. Session-This scopes a bean definition to an HTTP session. Global Session-This scopes a bean definition to a global HTTP session. <bean name=“student” class=“Student” scope=“prototype”/>
  • 19. Singleton Scope  Default scope-if we don’t define anything in scope spring construct automatically to Singleton Scope  With this what does it mean that, even though you call an instance of the bean using spring framework for one or more times all the time only one instance will return. Single student instance ctx.getBean(“student”) Spring Container
  • 20. Prototype Scope Spring Container Multiple beans For ‘n’ number of request using ctx.getBean(“student”) you get ‘n’ number of instance to the application that means every call you get new instance of bean.
  • 21. Method Injection-Method Replace class MobileStore { public String buyMobile() { return “Bought a Mobile Phone”; } } class MobileStoreReplacer implements MethodReplacer { public Object reimplement(Object obj,Method method,Object[]args) throws Throwable { return “Bought an iPhone”; } } <bean id=“mobileStore” class “MobileStore”> <replace-method name=“buyMobile” replacer=“mobileStoreReplacer”/></bean> <bean id=“mobileStoreReplacer” class “MobileStoreReplacer”/>
  • 22. On run time when ever you get a bean of mobile Store through spring framework and call buyMobile.Spring understands it need to replace buyMobile to MobileStoreReplacer.
  • 26. Spring - Bean Definition Inheritance  A bean definition can contain a lot of configuration information, including constructor arguments, property values and so on.  Spring Bean definition inheritance has nothing to do with Java class inheritance but the inheritance concept is same.  Following is the configuration file Beans.xml where we defined "helloWorld" bean which has two properties message1 and message2. Next "helloIndia" bean has been defined as a child of "helloWorld" bean by using parent attribute. The child bean inherits message2 property as is, and overrides message1 property and introduces one more property message3.
  • 27. Beans.xml <?xml version = "1.0" encoding = "UTF-8"?> <bean id = "helloWorld" class = "com.tutorialspoint.HelloWorld"> <property name = "message1" value = "Hello World!"/> <property name = "message2" value = "Hello Second World!"/> </bean> <bean id ="helloIndia" class = "com.tutorialspoint.HelloIndia" parent = "helloWorld"> <property name = "message1" value = "Hello India!"/> <property name = "message3" value = "Namaste India!"/> </bean> </beans>
  • 28. HelloWorld.java public class HelloWorld { private String message1; private String message2; public void setMessage1(String message) { this.message1 = message; } public void setMessage2(String message) { this.message2 = message; } public void getMessage1() { System.out.println("World Message1 : " + message1); } public void getMessage2() { System.out.println("World Message2 : " + message2);} }
  • 29. HelloIndia.java public class HelloIndia { private String message1; private String message2; private String message3; public void setMessage1(String message) { this.message1 = message; } public void setMessage2(String message) { this.message2 = message; } public void setMessage3(String message) { this.message3 = message; } public void getMessage1(){ System.out.println ("India Message1 : " + message1); } public void getMessage2(){ System.out.println("India Message2 : " + message2); } public void getMessage3(){ System.out.println("India Message3 : " + message3); } }
  • 30. MainApp.java import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class MainApp { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml"); HelloWorld objA = (HelloWorld) context.getBean("helloWorld"); objA.getMessage1(); objA.getMessage2(); HelloIndia objB = (HelloIndia) context.getBean("helloIndia"); objB.getMessage1(); objB.getMessage2(); objB.getMessage3(); } }
  • 31. output World Message1 : Hello World! World Message2 : Hello Second World! India Message1 : Hello India! India Message2 : Hello Second World! India Message3 : Namaste India!