SlideShare a Scribd company logo
Mahika Tutorials
Spring Framework
Tutorials
Mahika Tutorials
Using MessageSource
to get text from properties file
INTRODUCTIONTO
SPRING
Mahika Tutorials
Mahika Tutorials
 Spring is a light weight and open source framework created by Rod
Johnson in 2003.
Mahika Tutorials
Spring Application
Spring jars
 Spring framework makes the development of Java/JavaEE application
easy.
Mahika Tutorials
Dtababase Connectivity
Transaction Management
Dependency Injection
AOP
 Spring can be thought of as a framework of frameworks because it provides
support to various frameworks such as Struts, Hibernate, EJB, JSF etc.
Mahika Tutorials
Spring
JSF
EJB
Hibernate
Struts
 Spring enables you to build applications from “plain old Java objects”
(POJOs).
Mahika Tutorials
 Spring framework is said to be a non-invasive means it doesn’t force a
programmer to extend or implement their class from any predefined
class or interface given by Spring API.
Mahika Tutorials
 Spring applications are loosely coupled because of dependency
injection and Inversion of Control(IOC).
Mahika Tutorials
Employee
Address address;
Employee(){
address=newAddress(“XYZ Street ,”Pune”);
}
Employee
Address address;
Third Party
Address
instance
Tight Coupling Loose Coupling
Spring Modules
Mahika Tutorials
Core Container
Mahika Tutorials
 Core and Beans:These modules provide IOC and Dependency Injection features.
 Context:This module supports internationalization (I18N), EJB, JMS, Basic Remoting.
 SpEL: It is an extension to the EL defined in JSP. It provides support to setting and getting property values,
method invocation, accessing collections, named variables, logical and arithmetic operators, retrieval of
objects by name etc.
Data Access / Integration-
Mahika Tutorials
 These modules basically provide support to interact with the database.
 The JDBC module removes the need to do tedious JDBC coding.
 ORM module is used to tie up with ORM tools such as hibernate.
Web
Mahika Tutorials
 These modules provide support to create web application.
Test
 This module supports the testing of Spring components with JUnit orTestNG.
Mahika Tutorials
Mahika Tutorials
Dependency Injection &IOC
Dependency Injection
 Dependency Injection (DI) is a software design pattern that deals with how components get hold of their
dependencies.
 A class X has a dependency to classY, if class X uses classY as a variable.
 Java components / classes should be as independent as possible of other Java classes.
 This increases the possibility to reuse these classes and to test them independently of other classes(UnitTesting).
 Dependency injection is a style of object configuration in which an object’s fields are set by an external entity, in other
words objects are configured by an external entity.
 Dependency injection is an alternative to having the object configure itself.
Mahika Tutorials
class X
{
Y y;
……………
}
Dependency Injection and Inversion of Control
Mahika Tutorials
A
C
B
Dependency
A
C
B
Injection
Inversion of Control is a principle by which the control of objects is transferred to a
container or framework.
Dependency injection is a pattern through which IoC is implemented, where the control
being inverted is the setting of object’s dependencies.
The act of connecting objects with other objects, or “injecting” objects into other objects,
is done by container rather than by the objects themselves.
A class should not configure itself but should be configured from outside.
Mahika Tutorials
Dependency Injection and Inversion of Control
Dependency Injection and Inversion of Control
 IOC makes the code loosely coupled. In such case, there is no need to
modify the code if our logic is moved to new environment.
 IOC makes the application easy to test.
 In Spring framework, IOC container is responsible to inject the
dependency. We provide metadata to the IOC container either by XML
file or annotation
Mahika Tutorials
Dependency Injection
Spring framework provides two ways to inject dependency
By Constructor (Constructor Injection)-In the case of constructor-based dependency
injection, the container will invoke a constructor with arguments each representing a
dependency we want to set.
By Setter method (Setter Injection)-For setter-based DI, the container will call setter
methods of our class.
Mahika Tutorials
class Employee{
Address address;
Employee(){
address=newAddress(“XYZ Street”, ”Pune”, ”MH”);
}
…………………..
}
With IOC (setter Injection)Without IOC
class Employee{
Address address;
public void setAddress(Address address){
this.address=address;
}
………
}
With IOC (constructor Injection)
class Employee{
Address address;
Employee(Address address){
this.address=address;
………
}
}
Mahika Tutorials
Mahika Tutorials
BeanFactory & AplicationContext
IOC
 In Spring framework, IOC container is responsible to inject the dependencies.We provide metadata
to the IOC container either by XML file or annotation.
 The IoC container is responsible to instantiate, configure and assemble the objects.
Mahika Tutorials
BeanFactory
ApplicationContext
IOC
containers
BeanFactory
Mahika Tutorials
 Spring BeanFactory Container is the simplest container which provides basic support for DI.
 It is defined by org.springframework.beans.factory.BeanFactory interface.
 There are many implementations of BeanFactory interface . The most commonly used
BeanFactory implementation is –
org.springframework.beans.factory.xml.XmlBeanFactory
 Example-
Resource resource=new ClassPathResource(“Beans.xml");
BeanFactory factory=new XmlBeanFactory(resource);
 The Resource interface has many implementaions. Two mainly used are:
1)org.springframework.core.io.FileSystemResource :Loads the resource from underlying file
system.
Example-
BeanFactory bfObj = new XmlBeanFactory(new FileSystemResource ("c:/beansconfig.xml"));
2)org.springframework.core.io.ClassPathResource:Loads the resource from classpath.
ApplicationContext
The ApplicationContext container is Spring’s advanced container.
It is defined by org.springframework.context.ApplicationContext interface.
The ApplicationContext interface is built on top of the BeanFactory interface.
 It adds some extra functionality than BeanFactory such as simple integration with
Spring's AOP, message resource handling (for I18N), event propagation etc.
There are many implementations of ApplicationContext interface .The most
commonly used ApplicationContext implementation is –
org.springframework.context.support.ClassPathXmlApplicationContext
 Example-
ApplicationContext context=new ClassPathXmlApplicationContext("Beans.xml");
Mahika Tutorials
Mahika Tutorials
Mahika Tutorials
Spring Autowiring
Autowiring in Spring
Mahika Tutorials
 Autowiring means injecting the object dependency implicitly.
 It internally uses setter or constructor injection.
 It works with reference only.
 Autowiring can't be used to inject primitive and string values.
 By default autowiring is disabled in spring framework.
 Autowiring can be performed by either using “autowire” attribute in <bean> or by using @Autowired annotation.
Without Autowiring
Mahika Tutorials
public class Employee {
private int id;
private String name;
private Address address;
…….
}
…….
<bean id="address" class="com.tutorials.demo.Address">
<property name="street" value="Park Street"></property>
<property name="city" value="Pune"></property>
<property name="state" value="Maharashtra"></property>
</bean>
<bean id="emp" class="com.tutorials.demo.Employee">
<property name="id" value="111"></property>
<property name="name" value="Ram"></property>
<property name="address" ref="address"></property>
</bean>
……….
With Autowiring
Mahika Tutorials
public class Employee {
private int id;
private String name;
private Address address;
…….
}
…….
<bean id="address" class="com.tutorials.demo.Address">
<property name="street" value="Park Street"></property>
<property name="city" value="Pune"></property>
<property name="state" value="Maharashtra"></property>
</bean>
<bean id="emp" class="com.tutorials.demo.Employee“ autowire=“byName">
<property name="id" value="111"></property>
<property name="name" value="Ram"></property>
</bean>
……….
Autowiring modes
Mahika Tutorials
No. Mode Description
1) no It is the default autowiring mode. It means no autowiring bydefault.
2) byName The byName mode injects the object dependency according to name of the bean. In such
case, property name and bean name must be same. It internally calls setter method.
3) byType The byType mode injects the object dependency according to type. So property name and
bean name can be different. It internally calls setter method.
4) constructor The constructor mode injects the dependency by calling the constructor of the class. It calls
the constructor having large number of parameters.
5) autodetect It is deprecated since Spring 3.
Mahika Tutorials
Mahika Tutorials
Bean Scopes
Autowiring in Spring
Mahika Tutorials
 Autowiring means injecting the object dependency implicitly.
 It internally uses setter or constructor injection.
 It works with reference only.
 Autowiring can't be used to inject primitive and string values.
 By default autowiring is disabled in spring framework.
 Autowiring can be performed by either using “autowire” attribute in <bean> or by using @Autowired annotation.
Mahika Tutorials
Ad

More Related Content

What's hot (19)

Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
Raveendra R
 
EJB Clients
EJB ClientsEJB Clients
EJB Clients
Roy Antony Arnold G
 
Introduction to JPA Framework
Introduction to JPA FrameworkIntroduction to JPA Framework
Introduction to JPA Framework
Collaboration Technologies
 
Hibernate II
Hibernate IIHibernate II
Hibernate II
People Strategists
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
Aneega
 
Data access
Data accessData access
Data access
Joshua Yoon
 
Functional Dependency Injection in C#
Functional Dependency Injection in C#Functional Dependency Injection in C#
Functional Dependency Injection in C#
Thomas Jaskula
 
JPA For Beginner's
JPA For Beginner'sJPA For Beginner's
JPA For Beginner's
NarayanaMurthy Ganashree
 
Spring Framework-II
Spring Framework-IISpring Framework-II
Spring Framework-II
People Strategists
 
Introduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examplesIntroduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examples
ecosio GmbH
 
Introduction to Hibernate
Introduction to HibernateIntroduction to Hibernate
Introduction to Hibernate
Krishnakanth Goud
 
Types of Dependency Injection in Spring
Types of Dependency Injection in SpringTypes of Dependency Injection in Spring
Types of Dependency Injection in Spring
Sunil kumar Mohanty
 
Overview of JEE Technology
Overview of JEE TechnologyOverview of JEE Technology
Overview of JEE Technology
People Strategists
 
Hibernate tutorial for beginners
Hibernate tutorial for beginnersHibernate tutorial for beginners
Hibernate tutorial for beginners
Rahul Jain
 
Technical Interview
Technical InterviewTechnical Interview
Technical Interview
prashant patel
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
Syed Shahul
 
Massively Scalable Applications - TechFerry
Massively Scalable Applications - TechFerryMassively Scalable Applications - TechFerry
Massively Scalable Applications - TechFerry
TechFerry
 
Spring Framework - III
Spring Framework - IIISpring Framework - III
Spring Framework - III
People Strategists
 
Introduction to OO, Java and Eclipse/WebSphere
Introduction to OO, Java and Eclipse/WebSphereIntroduction to OO, Java and Eclipse/WebSphere
Introduction to OO, Java and Eclipse/WebSphere
eLink Business Innovations
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
Raveendra R
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
Aneega
 
Functional Dependency Injection in C#
Functional Dependency Injection in C#Functional Dependency Injection in C#
Functional Dependency Injection in C#
Thomas Jaskula
 
Introduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examplesIntroduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examples
ecosio GmbH
 
Types of Dependency Injection in Spring
Types of Dependency Injection in SpringTypes of Dependency Injection in Spring
Types of Dependency Injection in Spring
Sunil kumar Mohanty
 
Hibernate tutorial for beginners
Hibernate tutorial for beginnersHibernate tutorial for beginners
Hibernate tutorial for beginners
Rahul Jain
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
Syed Shahul
 
Massively Scalable Applications - TechFerry
Massively Scalable Applications - TechFerryMassively Scalable Applications - TechFerry
Massively Scalable Applications - TechFerry
TechFerry
 
Introduction to OO, Java and Eclipse/WebSphere
Introduction to OO, Java and Eclipse/WebSphereIntroduction to OO, Java and Eclipse/WebSphere
Introduction to OO, Java and Eclipse/WebSphere
eLink Business Innovations
 

Similar to Spring FrameWork Tutorials Java Language (20)

Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
Collaboration Technologies
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Rajind Ruparathna
 
Spring IOC and DAO
Spring IOC and DAOSpring IOC and DAO
Spring IOC and DAO
AnushaNaidu
 
Unit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxUnit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptx
DrYogeshDeshmukh1
 
Spring core
Spring coreSpring core
Spring core
Harshit Choudhary
 
Dependency Injection, Zend Framework and Symfony Container
Dependency Injection, Zend Framework and Symfony ContainerDependency Injection, Zend Framework and Symfony Container
Dependency Injection, Zend Framework and Symfony Container
Diego Lewin
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
Vinay Kumar
 
[2015/2016] Require JS and Handlebars JS
[2015/2016] Require JS and Handlebars JS[2015/2016] Require JS and Handlebars JS
[2015/2016] Require JS and Handlebars JS
Ivano Malavolta
 
OOPs Interview Questions PDF By ScholarHat
OOPs Interview Questions PDF By ScholarHatOOPs Interview Questions PDF By ScholarHat
OOPs Interview Questions PDF By ScholarHat
Scholarhat
 
Java J2EE Interview Question Part 2
Java J2EE Interview Question Part 2Java J2EE Interview Question Part 2
Java J2EE Interview Question Part 2
Mindsmapped Consulting
 
Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2
javatrainingonline
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
Krishnaov
 
2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf
DeoDuaNaoHet
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
ThirupathiReddy Vajjala
 
Spring from a to Z
Spring from  a to ZSpring from  a to Z
Spring from a to Z
sang nguyen
 
02 objective-c session 2
02  objective-c session 202  objective-c session 2
02 objective-c session 2
Amr Elghadban (AmrAngry)
 
Ef Poco And Unit Testing
Ef Poco And Unit TestingEf Poco And Unit Testing
Ef Poco And Unit Testing
James Phillips
 
JAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp conceptsJAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp concepts
Rahul Malhotra
 
CDI @javaonehyderabad
CDI @javaonehyderabadCDI @javaonehyderabad
CDI @javaonehyderabad
Prasad Subramanian
 
Toms introtospring mvc
Toms introtospring mvcToms introtospring mvc
Toms introtospring mvc
Guo Albert
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Rajind Ruparathna
 
Spring IOC and DAO
Spring IOC and DAOSpring IOC and DAO
Spring IOC and DAO
AnushaNaidu
 
Unit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxUnit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptx
DrYogeshDeshmukh1
 
Dependency Injection, Zend Framework and Symfony Container
Dependency Injection, Zend Framework and Symfony ContainerDependency Injection, Zend Framework and Symfony Container
Dependency Injection, Zend Framework and Symfony Container
Diego Lewin
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
Vinay Kumar
 
[2015/2016] Require JS and Handlebars JS
[2015/2016] Require JS and Handlebars JS[2015/2016] Require JS and Handlebars JS
[2015/2016] Require JS and Handlebars JS
Ivano Malavolta
 
OOPs Interview Questions PDF By ScholarHat
OOPs Interview Questions PDF By ScholarHatOOPs Interview Questions PDF By ScholarHat
OOPs Interview Questions PDF By ScholarHat
Scholarhat
 
Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2
javatrainingonline
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
Krishnaov
 
2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf
DeoDuaNaoHet
 
Spring from a to Z
Spring from  a to ZSpring from  a to Z
Spring from a to Z
sang nguyen
 
Ef Poco And Unit Testing
Ef Poco And Unit TestingEf Poco And Unit Testing
Ef Poco And Unit Testing
James Phillips
 
JAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp conceptsJAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp concepts
Rahul Malhotra
 
Toms introtospring mvc
Toms introtospring mvcToms introtospring mvc
Toms introtospring mvc
Guo Albert
 
Ad

Recently uploaded (20)

Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxbMain cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
SunilSingh610661
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
How to use nRF24L01 module with Arduino
How to use nRF24L01 module with ArduinoHow to use nRF24L01 module with Arduino
How to use nRF24L01 module with Arduino
CircuitDigest
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIHlecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
Abodahab
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Journal of Soft Computing in Civil Engineering
 
New Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdfNew Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdf
mohamedezzat18803
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxbMain cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
SunilSingh610661
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
How to use nRF24L01 module with Arduino
How to use nRF24L01 module with ArduinoHow to use nRF24L01 module with Arduino
How to use nRF24L01 module with Arduino
CircuitDigest
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIHlecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
Abodahab
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
New Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdfNew Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdf
mohamedezzat18803
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Ad

Spring FrameWork Tutorials Java Language

  • 2. Mahika Tutorials Using MessageSource to get text from properties file
  • 4.  Spring is a light weight and open source framework created by Rod Johnson in 2003. Mahika Tutorials Spring Application Spring jars
  • 5.  Spring framework makes the development of Java/JavaEE application easy. Mahika Tutorials Dtababase Connectivity Transaction Management Dependency Injection AOP
  • 6.  Spring can be thought of as a framework of frameworks because it provides support to various frameworks such as Struts, Hibernate, EJB, JSF etc. Mahika Tutorials Spring JSF EJB Hibernate Struts
  • 7.  Spring enables you to build applications from “plain old Java objects” (POJOs). Mahika Tutorials
  • 8.  Spring framework is said to be a non-invasive means it doesn’t force a programmer to extend or implement their class from any predefined class or interface given by Spring API. Mahika Tutorials
  • 9.  Spring applications are loosely coupled because of dependency injection and Inversion of Control(IOC). Mahika Tutorials Employee Address address; Employee(){ address=newAddress(“XYZ Street ,”Pune”); } Employee Address address; Third Party Address instance Tight Coupling Loose Coupling
  • 11. Core Container Mahika Tutorials  Core and Beans:These modules provide IOC and Dependency Injection features.  Context:This module supports internationalization (I18N), EJB, JMS, Basic Remoting.  SpEL: It is an extension to the EL defined in JSP. It provides support to setting and getting property values, method invocation, accessing collections, named variables, logical and arithmetic operators, retrieval of objects by name etc.
  • 12. Data Access / Integration- Mahika Tutorials  These modules basically provide support to interact with the database.  The JDBC module removes the need to do tedious JDBC coding.  ORM module is used to tie up with ORM tools such as hibernate.
  • 13. Web Mahika Tutorials  These modules provide support to create web application. Test  This module supports the testing of Spring components with JUnit orTestNG.
  • 16. Dependency Injection  Dependency Injection (DI) is a software design pattern that deals with how components get hold of their dependencies.  A class X has a dependency to classY, if class X uses classY as a variable.  Java components / classes should be as independent as possible of other Java classes.  This increases the possibility to reuse these classes and to test them independently of other classes(UnitTesting).  Dependency injection is a style of object configuration in which an object’s fields are set by an external entity, in other words objects are configured by an external entity.  Dependency injection is an alternative to having the object configure itself. Mahika Tutorials class X { Y y; …………… }
  • 17. Dependency Injection and Inversion of Control Mahika Tutorials A C B Dependency A C B Injection
  • 18. Inversion of Control is a principle by which the control of objects is transferred to a container or framework. Dependency injection is a pattern through which IoC is implemented, where the control being inverted is the setting of object’s dependencies. The act of connecting objects with other objects, or “injecting” objects into other objects, is done by container rather than by the objects themselves. A class should not configure itself but should be configured from outside. Mahika Tutorials Dependency Injection and Inversion of Control
  • 19. Dependency Injection and Inversion of Control  IOC makes the code loosely coupled. In such case, there is no need to modify the code if our logic is moved to new environment.  IOC makes the application easy to test.  In Spring framework, IOC container is responsible to inject the dependency. We provide metadata to the IOC container either by XML file or annotation Mahika Tutorials
  • 20. Dependency Injection Spring framework provides two ways to inject dependency By Constructor (Constructor Injection)-In the case of constructor-based dependency injection, the container will invoke a constructor with arguments each representing a dependency we want to set. By Setter method (Setter Injection)-For setter-based DI, the container will call setter methods of our class. Mahika Tutorials class Employee{ Address address; Employee(){ address=newAddress(“XYZ Street”, ”Pune”, ”MH”); } ………………….. } With IOC (setter Injection)Without IOC class Employee{ Address address; public void setAddress(Address address){ this.address=address; } ……… } With IOC (constructor Injection) class Employee{ Address address; Employee(Address address){ this.address=address; ……… } }
  • 22. Mahika Tutorials BeanFactory & AplicationContext
  • 23. IOC  In Spring framework, IOC container is responsible to inject the dependencies.We provide metadata to the IOC container either by XML file or annotation.  The IoC container is responsible to instantiate, configure and assemble the objects. Mahika Tutorials BeanFactory ApplicationContext IOC containers
  • 24. BeanFactory Mahika Tutorials  Spring BeanFactory Container is the simplest container which provides basic support for DI.  It is defined by org.springframework.beans.factory.BeanFactory interface.  There are many implementations of BeanFactory interface . The most commonly used BeanFactory implementation is – org.springframework.beans.factory.xml.XmlBeanFactory  Example- Resource resource=new ClassPathResource(“Beans.xml"); BeanFactory factory=new XmlBeanFactory(resource);  The Resource interface has many implementaions. Two mainly used are: 1)org.springframework.core.io.FileSystemResource :Loads the resource from underlying file system. Example- BeanFactory bfObj = new XmlBeanFactory(new FileSystemResource ("c:/beansconfig.xml")); 2)org.springframework.core.io.ClassPathResource:Loads the resource from classpath.
  • 25. ApplicationContext The ApplicationContext container is Spring’s advanced container. It is defined by org.springframework.context.ApplicationContext interface. The ApplicationContext interface is built on top of the BeanFactory interface.  It adds some extra functionality than BeanFactory such as simple integration with Spring's AOP, message resource handling (for I18N), event propagation etc. There are many implementations of ApplicationContext interface .The most commonly used ApplicationContext implementation is – org.springframework.context.support.ClassPathXmlApplicationContext  Example- ApplicationContext context=new ClassPathXmlApplicationContext("Beans.xml"); Mahika Tutorials
  • 28. Autowiring in Spring Mahika Tutorials  Autowiring means injecting the object dependency implicitly.  It internally uses setter or constructor injection.  It works with reference only.  Autowiring can't be used to inject primitive and string values.  By default autowiring is disabled in spring framework.  Autowiring can be performed by either using “autowire” attribute in <bean> or by using @Autowired annotation.
  • 29. Without Autowiring Mahika Tutorials public class Employee { private int id; private String name; private Address address; ……. } ……. <bean id="address" class="com.tutorials.demo.Address"> <property name="street" value="Park Street"></property> <property name="city" value="Pune"></property> <property name="state" value="Maharashtra"></property> </bean> <bean id="emp" class="com.tutorials.demo.Employee"> <property name="id" value="111"></property> <property name="name" value="Ram"></property> <property name="address" ref="address"></property> </bean> ……….
  • 30. With Autowiring Mahika Tutorials public class Employee { private int id; private String name; private Address address; ……. } ……. <bean id="address" class="com.tutorials.demo.Address"> <property name="street" value="Park Street"></property> <property name="city" value="Pune"></property> <property name="state" value="Maharashtra"></property> </bean> <bean id="emp" class="com.tutorials.demo.Employee“ autowire=“byName"> <property name="id" value="111"></property> <property name="name" value="Ram"></property> </bean> ……….
  • 31. Autowiring modes Mahika Tutorials No. Mode Description 1) no It is the default autowiring mode. It means no autowiring bydefault. 2) byName The byName mode injects the object dependency according to name of the bean. In such case, property name and bean name must be same. It internally calls setter method. 3) byType The byType mode injects the object dependency according to type. So property name and bean name can be different. It internally calls setter method. 4) constructor The constructor mode injects the dependency by calling the constructor of the class. It calls the constructor having large number of parameters. 5) autodetect It is deprecated since Spring 3.
  • 34. Autowiring in Spring Mahika Tutorials  Autowiring means injecting the object dependency implicitly.  It internally uses setter or constructor injection.  It works with reference only.  Autowiring can't be used to inject primitive and string values.  By default autowiring is disabled in spring framework.  Autowiring can be performed by either using “autowire” attribute in <bean> or by using @Autowired annotation.