SlideShare a Scribd company logo
1 of 16
Spring from A to ?
Introduction to Spring Framework
Spring Framework is a Java platform that provides comprehensive infrastructure
support for developing Java applications. Spring handles the infrastructure so you
can focus on your application.
SOLID
 Single responsibility principle
 Open/closed principle
 Liskov Substitution Principle
 Interface Segregation Principle
 Dependency inversion principle
Modules
Dependency Injection and Inversion of
Control
 IoC is also known as dependency
injection (DI).
 Dependency injection (DI) is a process
whereby objects define their dependencies
 In Spring, the objects that form the
backbone of your application and that are
managed by the Spring IoC container are
called beans.
 Interface org.springframework.context.Ap
plicationContext represents the Spring IoC
containe
Bean overview
Property Explained in...
class Ex: com.tcbs.OrderService
name
camel-cased from then on. Examples of such names would be (without
quotes) 'accountManager','accountService', 'userDao', 'loginController'
scope singleton, prototype, request, session, global session
constructor arguments
properties
autowiring mode Name,type, constructor
lazy-initialization mode
ApplicationContext implementations eagerly create and configure all singleton beans as part of
the initialization process
initialization method
destruction method
Bean scopes
Scope Description
singleton
(Default) Scopes a single bean definition to a single
object instance per Spring IoC container.
prototype
Scopes a single bean definition to any number of object
instances.
request
Scopes a single bean definition to the lifecycle of a
single HTTP request; that is, each HTTP request has its
own instance of a bean created off the back of a single
bean definition. Only valid in the context of a web-
aware Spring ApplicationContext.
session
Scopes a single bean definition to the lifecycle of an
HTTP Session. Only valid in the context of a web-aware
Spring ApplicationContext.
global session
Scopes a single bean definition to the lifecycle of a
global HTTP Session. Typically only valid when used in a
portlet context. Only valid in the context of a web-
aware Spring ApplicationContext.
Autowiring collaborators
Mode Explanation
no
(Default) No autowiring. Bean references must be defined via a ref element. Changing the default
setting is not recommended for larger deployments, because specifying collaborators explicitly gives
greater control and clarity. To some extent, it documents the structure of a system.
byName
Autowiring by property name. Spring looks for a bean with the same name as the property that needs
to be autowired. For example, if a bean definition is set to autowire by name, and it contains
a master property (that is, it has a setMaster(..) method), Spring looks for a bean definition
named master, and uses it to set the property.
byType
Allows a property to be autowired if exactly one bean of the property type exists in the container. If
more than one exists, a fatal exception is thrown, which indicates that you may not
use byType autowiring for that bean. If there are no matching beans, nothing happens; the property
is not set.
constructor
Analogous to byType, but applies to constructor arguments. If there is not exactly one bean of the
constructor argument type in the container, a fatal error is raised.
AOP Concepts
 Aspect – a standard code/feature that is scattered
across multiple places in the application and is
typically different than the actual Business Logic
(for example, Transaction management). Each
aspect focuses on a specific cross-cutting
functionality
 Joinpoint – it’s a particular point during execution
of programs like method execution, constructor
call, or field assignment
 Advice – the action taken by the aspect in a
specific joinpoint
 Pointcut – a regular expression that matches a
joinpoint. Each time any join point matches a
pointcut, a specified advice associated with that
pointcut is executed
 Weaving – the process of linking aspects with
targeted objects to create an advised object
Proxying mechanisms
 Spring AOP uses either JDK dynamic
proxies
 or CGLIB to create the proxy for a given
target object
 All of the interfaces implemented by the
target type will be proxied. If the target
object does not implement any interfaces
then a CGLIB proxy will be created.
Spring Expression Language (SpEL)
Spring annotations
Spring annotations
 @Service: Annotate all your service classes with @Service. All your business logic
should be in Service classes.
 @Repository: Annotate all your DAO classes with @Repository. All your database
access logic should be in DAO classes.
 @Component: Annotate your other components (for example REST resource
classes) with @Component.
 @Autowired: Let Spring auto-wire other beans into your classes using @Autowired
annotation.
 @Transactional: Configure your transactions with @Transactional spring
annotation.
 @Scope: As with Spring-managed components in general, the default and most
common scope for autodetected components is singleton. To change this default
behavior, use @Scope spring annotation.
Spring annotations
 @Controller: Annotate your controller classes with @Controller.
 @RequestMapping: spring annotation to map URLs onto an entire class or a
particular handler method.
 @PathVariable: spring annotation on a method argument to bind it to the value of
a URI template variable.
 @RequestParam: You can bind request parameters to method variables using
spring annotation @RequestParam.
 @ModelAttribute: An @ModelAttribute on a method argument indicates the
argument should be retrieved from the model.
 @SessionAttributes: spring annotation declares session attributes. This will
typically list the names of model attributes which should be transparently stored
in the session, serving as form-backing beans between subsequent requests.
Spring annotations
 @Bean(scope=DefaultScopes.PROTOTYPE): The DefaultScopes class
provides string constants for each of these four scopes. SINGLETON is
the default, and can be overridden by supplying the scope attribute to
@Bean annotation
 @Qualifier: Qualifie with the name of the specific implementation.
Springboot
 https://start.spring.io/

More Related Content

What's hot

.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13aminmesbahi
 
.NET Core, ASP.NET Core Course, Session 14
.NET Core, ASP.NET Core Course, Session 14.NET Core, ASP.NET Core Course, Session 14
.NET Core, ASP.NET Core Course, Session 14aminmesbahi
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Hitesh-Java
 
Scope demystified - AngularJS
Scope demystified - AngularJSScope demystified - AngularJS
Scope demystified - AngularJSSumanth krishna
 
The spring framework
The spring frameworkThe spring framework
The spring frameworkManav Prasad
 
Spring MVC Architecture Tutorial
Spring MVC Architecture TutorialSpring MVC Architecture Tutorial
Spring MVC Architecture TutorialJava Success Point
 
Spring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topicsSpring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topicsGuy Nir
 
Spring IOC and DAO
Spring IOC and DAOSpring IOC and DAO
Spring IOC and DAOAnushaNaidu
 
JSF 2.3: Integration with Front-End Frameworks
JSF 2.3: Integration with Front-End FrameworksJSF 2.3: Integration with Front-End Frameworks
JSF 2.3: Integration with Front-End FrameworksIan Hlavats
 
Spring framework Controllers and Annotations
Spring framework   Controllers and AnnotationsSpring framework   Controllers and Annotations
Spring framework Controllers and AnnotationsAnuj Singh Rajput
 
.NET Core, ASP.NET Core Course, Session 15
.NET Core, ASP.NET Core Course, Session 15.NET Core, ASP.NET Core Course, Session 15
.NET Core, ASP.NET Core Course, Session 15aminmesbahi
 
Spring Portlet MVC
Spring Portlet MVCSpring Portlet MVC
Spring Portlet MVCJohn Lewis
 
Introduction to Spring's Dependency Injection
Introduction to Spring's Dependency InjectionIntroduction to Spring's Dependency Injection
Introduction to Spring's Dependency InjectionRichard Paul
 

What's hot (20)

Oracle application-development-framework-best-practices
Oracle application-development-framework-best-practicesOracle application-development-framework-best-practices
Oracle application-development-framework-best-practices
 
.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13
 
.NET Core, ASP.NET Core Course, Session 14
.NET Core, ASP.NET Core Course, Session 14.NET Core, ASP.NET Core Course, Session 14
.NET Core, ASP.NET Core Course, Session 14
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
 
Spring & hibernate
Spring & hibernateSpring & hibernate
Spring & hibernate
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Scope demystified - AngularJS
Scope demystified - AngularJSScope demystified - AngularJS
Scope demystified - AngularJS
 
The spring framework
The spring frameworkThe spring framework
The spring framework
 
Spring MVC 5 & Hibernate 5 Integration
Spring MVC 5 & Hibernate 5 IntegrationSpring MVC 5 & Hibernate 5 Integration
Spring MVC 5 & Hibernate 5 Integration
 
Maven
MavenMaven
Maven
 
Spring MVC Architecture Tutorial
Spring MVC Architecture TutorialSpring MVC Architecture Tutorial
Spring MVC Architecture Tutorial
 
Spring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topicsSpring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topics
 
Spring IOC and DAO
Spring IOC and DAOSpring IOC and DAO
Spring IOC and DAO
 
JSF 2.3: Integration with Front-End Frameworks
JSF 2.3: Integration with Front-End FrameworksJSF 2.3: Integration with Front-End Frameworks
JSF 2.3: Integration with Front-End Frameworks
 
Spring framework Controllers and Annotations
Spring framework   Controllers and AnnotationsSpring framework   Controllers and Annotations
Spring framework Controllers and Annotations
 
Android meetup
Android meetupAndroid meetup
Android meetup
 
Spring MVC 3.0 Framework
Spring MVC 3.0 FrameworkSpring MVC 3.0 Framework
Spring MVC 3.0 Framework
 
.NET Core, ASP.NET Core Course, Session 15
.NET Core, ASP.NET Core Course, Session 15.NET Core, ASP.NET Core Course, Session 15
.NET Core, ASP.NET Core Course, Session 15
 
Spring Portlet MVC
Spring Portlet MVCSpring Portlet MVC
Spring Portlet MVC
 
Introduction to Spring's Dependency Injection
Introduction to Spring's Dependency InjectionIntroduction to Spring's Dependency Injection
Introduction to Spring's Dependency Injection
 

Similar to Spring from a to Z

Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2javatrainingonline
 
Spring Framework
Spring FrameworkSpring Framework
Spring Frameworknomykk
 
Spring training
Spring trainingSpring training
Spring trainingTechFerry
 
Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4than sare
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework tola99
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework Serhat Can
 
Sprint Portlet MVC Seminar
Sprint Portlet MVC SeminarSprint Portlet MVC Seminar
Sprint Portlet MVC SeminarJohn Lewis
 
Spring Basics
Spring BasicsSpring Basics
Spring BasicsEmprovise
 
Struts Intro Course(1)
Struts Intro Course(1)Struts Intro Course(1)
Struts Intro Course(1)wangjiaz
 
Spring (1)
Spring (1)Spring (1)
Spring (1)Aneega
 
Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1Michał Orman
 
Spring talk111204
Spring talk111204Spring talk111204
Spring talk111204ealio
 

Similar to Spring from a to Z (20)

Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2
 
Java J2EE Interview Question Part 2
Java J2EE Interview Question Part 2Java J2EE Interview Question Part 2
Java J2EE Interview Question Part 2
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
 
Spring 2
Spring 2Spring 2
Spring 2
 
Spring training
Spring trainingSpring training
Spring training
 
Spring mvc 2.0
Spring mvc 2.0Spring mvc 2.0
Spring mvc 2.0
 
Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
Struts N E W
Struts N E WStruts N E W
Struts N E W
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Sprint Portlet MVC Seminar
Sprint Portlet MVC SeminarSprint Portlet MVC Seminar
Sprint Portlet MVC Seminar
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
 
Struts Intro Course(1)
Struts Intro Course(1)Struts Intro Course(1)
Struts Intro Course(1)
 
MVC
MVCMVC
MVC
 
Spring (1)
Spring (1)Spring (1)
Spring (1)
 
Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1
 
Spring talk111204
Spring talk111204Spring talk111204
Spring talk111204
 
J2EE pattern 5
J2EE pattern 5J2EE pattern 5
J2EE pattern 5
 

More from sang nguyen

AMM, How it works.pdf
AMM, How it works.pdfAMM, How it works.pdf
AMM, How it works.pdfsang nguyen
 
Distributed data management challenges
Distributed data management challengesDistributed data management challenges
Distributed data management challengessang nguyen
 
Reactive programming
Reactive programmingReactive programming
Reactive programmingsang nguyen
 
Finding use case
Finding use caseFinding use case
Finding use casesang nguyen
 
Software - Information gathering
Software - Information gatheringSoftware - Information gathering
Software - Information gatheringsang nguyen
 
Business analysis-Software
Business analysis-SoftwareBusiness analysis-Software
Business analysis-Softwaresang nguyen
 
Alfresco overview EDM
Alfresco overview EDMAlfresco overview EDM
Alfresco overview EDMsang nguyen
 

More from sang nguyen (8)

AMM, How it works.pdf
AMM, How it works.pdfAMM, How it works.pdf
AMM, How it works.pdf
 
Distributed data management challenges
Distributed data management challengesDistributed data management challenges
Distributed data management challenges
 
Uml 2.x
Uml 2.xUml 2.x
Uml 2.x
 
Reactive programming
Reactive programmingReactive programming
Reactive programming
 
Finding use case
Finding use caseFinding use case
Finding use case
 
Software - Information gathering
Software - Information gatheringSoftware - Information gathering
Software - Information gathering
 
Business analysis-Software
Business analysis-SoftwareBusiness analysis-Software
Business analysis-Software
 
Alfresco overview EDM
Alfresco overview EDMAlfresco overview EDM
Alfresco overview EDM
 

Recently uploaded

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 

Recently uploaded (20)

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 

Spring from a to Z

  • 2. Introduction to Spring Framework Spring Framework is a Java platform that provides comprehensive infrastructure support for developing Java applications. Spring handles the infrastructure so you can focus on your application.
  • 3. SOLID  Single responsibility principle  Open/closed principle  Liskov Substitution Principle  Interface Segregation Principle  Dependency inversion principle
  • 5. Dependency Injection and Inversion of Control  IoC is also known as dependency injection (DI).  Dependency injection (DI) is a process whereby objects define their dependencies  In Spring, the objects that form the backbone of your application and that are managed by the Spring IoC container are called beans.  Interface org.springframework.context.Ap plicationContext represents the Spring IoC containe
  • 6. Bean overview Property Explained in... class Ex: com.tcbs.OrderService name camel-cased from then on. Examples of such names would be (without quotes) 'accountManager','accountService', 'userDao', 'loginController' scope singleton, prototype, request, session, global session constructor arguments properties autowiring mode Name,type, constructor lazy-initialization mode ApplicationContext implementations eagerly create and configure all singleton beans as part of the initialization process initialization method destruction method
  • 7. Bean scopes Scope Description singleton (Default) Scopes a single bean definition to a single object instance per Spring IoC container. prototype Scopes a single bean definition to any number of object instances. request Scopes a single bean definition to the lifecycle of a single HTTP request; that is, each HTTP request has its own instance of a bean created off the back of a single bean definition. Only valid in the context of a web- aware Spring ApplicationContext. session Scopes a single bean definition to the lifecycle of an HTTP Session. Only valid in the context of a web-aware Spring ApplicationContext. global session Scopes a single bean definition to the lifecycle of a global HTTP Session. Typically only valid when used in a portlet context. Only valid in the context of a web- aware Spring ApplicationContext.
  • 8. Autowiring collaborators Mode Explanation no (Default) No autowiring. Bean references must be defined via a ref element. Changing the default setting is not recommended for larger deployments, because specifying collaborators explicitly gives greater control and clarity. To some extent, it documents the structure of a system. byName Autowiring by property name. Spring looks for a bean with the same name as the property that needs to be autowired. For example, if a bean definition is set to autowire by name, and it contains a master property (that is, it has a setMaster(..) method), Spring looks for a bean definition named master, and uses it to set the property. byType Allows a property to be autowired if exactly one bean of the property type exists in the container. If more than one exists, a fatal exception is thrown, which indicates that you may not use byType autowiring for that bean. If there are no matching beans, nothing happens; the property is not set. constructor Analogous to byType, but applies to constructor arguments. If there is not exactly one bean of the constructor argument type in the container, a fatal error is raised.
  • 9. AOP Concepts  Aspect – a standard code/feature that is scattered across multiple places in the application and is typically different than the actual Business Logic (for example, Transaction management). Each aspect focuses on a specific cross-cutting functionality  Joinpoint – it’s a particular point during execution of programs like method execution, constructor call, or field assignment  Advice – the action taken by the aspect in a specific joinpoint  Pointcut – a regular expression that matches a joinpoint. Each time any join point matches a pointcut, a specified advice associated with that pointcut is executed  Weaving – the process of linking aspects with targeted objects to create an advised object
  • 10. Proxying mechanisms  Spring AOP uses either JDK dynamic proxies  or CGLIB to create the proxy for a given target object  All of the interfaces implemented by the target type will be proxied. If the target object does not implement any interfaces then a CGLIB proxy will be created.
  • 13. Spring annotations  @Service: Annotate all your service classes with @Service. All your business logic should be in Service classes.  @Repository: Annotate all your DAO classes with @Repository. All your database access logic should be in DAO classes.  @Component: Annotate your other components (for example REST resource classes) with @Component.  @Autowired: Let Spring auto-wire other beans into your classes using @Autowired annotation.  @Transactional: Configure your transactions with @Transactional spring annotation.  @Scope: As with Spring-managed components in general, the default and most common scope for autodetected components is singleton. To change this default behavior, use @Scope spring annotation.
  • 14. Spring annotations  @Controller: Annotate your controller classes with @Controller.  @RequestMapping: spring annotation to map URLs onto an entire class or a particular handler method.  @PathVariable: spring annotation on a method argument to bind it to the value of a URI template variable.  @RequestParam: You can bind request parameters to method variables using spring annotation @RequestParam.  @ModelAttribute: An @ModelAttribute on a method argument indicates the argument should be retrieved from the model.  @SessionAttributes: spring annotation declares session attributes. This will typically list the names of model attributes which should be transparently stored in the session, serving as form-backing beans between subsequent requests.
  • 15. Spring annotations  @Bean(scope=DefaultScopes.PROTOTYPE): The DefaultScopes class provides string constants for each of these four scopes. SINGLETON is the default, and can be overridden by supplying the scope attribute to @Bean annotation  @Qualifier: Qualifie with the name of the specific implementation.

Editor's Notes

  1. https://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/overview.html