SlideShare a Scribd company logo
1 of 21
Spring
Sujit Kumar
Zenolocity LLC
Copyright 2012-2024 @
Dependency Injection (IOC)
• Do not create your objects but describe how they
should be created.
• You don't directly connect your components and
services together in code but describe how they
are wired together in a configuration file.
• A container (in the case of the Spring framework,
the IOC container) is then responsible for hooking
it all up.
Types of Dependency injection
• Constructor Injection => Dependencies are
provided as constructor parameters.
• Setter Injection => Dependencies are assigned
through JavaBeans properties (ex: setter
methods).
Benefits of Spring
• Minimizes the amount of code in your application.
• Make your application more testable. IOC containers
make unit testing and switching implementations very
easy by manually allowing you to inject your own
objects into the object under test.
• Loose coupling is promoted.
• IOC containers support eager instantiation and lazy
loading of services.
• Use whatever modules you need, leave what you don’t
need.
• Enables POJO programming without any dependencies
on an Application Server like Tomcat or WebLogic.
Features of Spring
•

Lightweight:: spring is lightweight when it comes to size and transparency. The basic version of
spring framework is around 1MB. And the processing overhead is also very negligible.

•

Inversion of control (IOC): Loose coupling is achieved in spring using the technique Inversion of
Control. The objects give their dependencies instead of creating or looking for dependent objects.

•

Aspect oriented (AOP): Spring supports Aspect oriented programming and enables cohesive
development by separating application business logic from system services.

•

Container: Spring contains and manages the life cycle and configuration of application objects.

•

MVC Framework: Highly configurable and accommodates multiple view technologies like JSP,
Velocity and Tiles.

•

Transaction Management: Generic abstraction layer for transaction management with pluggable
transaction managers. Not tied to J2EE environments and it can be also used in container less
environments.

•

JDBC Exception Handling: The JDBC abstraction layer of the Spring offers a meaningful exception
hierarchy, which simplifies the error handling strategy. Integration with Hibernate, JDO, and iBATIS.
7 Modules of Spring
•

The core container: Bean Factory, Application Context, IOC/DI.

•

Spring context: Configuration file that provides context information to the Spring framework.
Includes enterprise services such as JNDI, JMS, e-mail, internalization, validation and scheduling
functionality.

•

Spring AOP: Most important uses are transaction management, security , logging, performance
metrics gathering.

•

Spring DAO: meaningful exception hierarchy for managing the exception handling and error
messages thrown by different database vendors.

•

Spring ORM: JDO, Hibernate and iBatis . All of these comply to Spring's generic transaction and
DAO exception hierarchies..

•

Spring Web module: The Web context module builds on top of the application context module,
providing contexts for Web-based applications.

•

Spring MVC framework: The Model-View-Controller (MVC) framework is a full-featured MVC
implementation for building Web applications.
Bean Factory
• Like a factory class that contains a collection of
beans. Holds bean definitions of multiple beans
within itself and then instantiates the bean
whenever asked for by clients.
• Can create associations between collaborating
objects as they are instantiated. This removes the
burden of configuration from bean itself and the
beans client.
• Manage the life cycle of a bean making calls to
custom initialization and destruction methods.
Bean Scopes in Spring
• singleton => single object instance per Spring IoC
container.
• prototype => new object instance whenever
requested.
• request => lifecycle of a single HTTP request
• session => lifecycle of a HTTP Session.
• global session => 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.
Application Context
• An Application Context is same as a bean factory.
Both load bean definitions, wire beans together
and dispense beans upon request.
• However, an Application Context is a more
advanced container and has a lot more
functionality:
• It provides a means for resolving text messages,
including support for internationalization.
• It provides a generic way to load file resources.
• It can publish events to beans that are registered
as listeners.
Common Implementations of the
Application Context
• ClassPathXmlApplicationContext : loads context definition
from an XML file located in the classpath, treating context
definitions as classpath resources.
ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");

• FileSystemXmlApplicationContext : loads context
definition from an XML file in the file system.
ApplicationContext context = new FileSystemXmlApplicationContext("bean.xml");

• XmlWebApplicationContext : It loads context definition
from an XML file contained within a web application.
Typical Spring Application
• An interface class containing abstract methods.
• One or more implementation classes that
implement the above interface with properties &
their setter and getter methods, method
implementations of the interface that it
implements.
• An XML file called Spring configuration file.
• Client program that uses the interface methods.
Spring JDBC
• Spring's JdbcTemplate is central class to
interact with a database through JDBC.
• Provides many convenience methods like:
1. Convert database data into primitives or
objects
2. Execute prepared and callable statements
3. Custom database error handling.
ORMs supported by Spring
•
•
•
•

Hibernate
iBatis
JPA (Java Persistence API)
JDO (Java Data Objects)
Access Hibernate using Spring
Two Options:
1. Inversion of Control with HibernateTemplate.
2. Extending HibernateDaoSupport and
applying an AOP Interceptor.
Spring Transaction Management
• Declarative transaction management => good
idea only if you have a large number of
transactional operations. It is non-invasive - keeps
transaction management code out of business
logic and is not difficult to configure.
• Programmatic transaction management => good
idea only if you have a small number of
transactional operations.
Spring AOP
• Modularize crosscutting concerns such as
transaction management, security, logging
and gathering performance metrics.
• The core construct of AOP is the aspect which
encapsulates behaviors affecting multiple
classes into reusable modules.
AOP Terms
•

Aspect: A modularization of a concern that cuts across multiple objects.
Transaction management is a good example of a crosscutting concern in J2EE
applications.

•

Join Point : A point during the execution of a program, such as the execution of a
method or the handling of an exception. In Spring AOP, a join point always
represents a method execution.

•

Pointcut: A predicate that matches join points. Advice is associated with a pointcut
expression and runs at any join point matched by the pointcut (for example, the
execution of a method with a certain name).

•

Advice: action taken by an aspect at a particular join point. Different types of
advice include "around," "before" and "after" advice. Model an advice as an
interceptor, maintaining a chain of interceptors "around" the join point.
AOP Terms (contd…)
• Target object: Object being advised by one or more aspects. Also referred
to as the advised object. Since Spring AOP is implemented using runtime
proxies, this object will always be a proxied object.
• AOP proxy: An object created by the AOP framework in order to
implement the aspect contracts (advise method executions and so on). In
the Spring Framework, an AOP proxy will be a JDK dynamic proxy or a
CGLIB proxy. Proxy creation is transparent to users of the schema-based
and @AspectJ styles of aspect declaration introduced in Spring 2.0.
• Weaving: Linking aspects with other application types or objects to create
an advised object. This can be done at compile time (using the AspectJ
compiler, for example), load time, or at runtime. Spring AOP, like other
pure Java AOP frameworks, performs weaving at runtime.
Types of Advice
•

Before advice: Advice that executes before a join point, but which does not have
the ability to prevent execution flow proceeding to the join point (unless it throws
an exception).

•

After returning advice: Advice to be executed after a join point completes
normally: for example, if a method returns without throwing an exception.

•

After throwing advice: Advice to be executed if a method exits by throwing an
exception.

•

After (finally) advice: Advice to be executed regardless of the means by which a
join point exits (normal or exceptional return).

•

Around advice: Advice that surrounds a join point such as a method invocation.
This is the most powerful kind of advice. Around advice can perform custom
behavior before and after the method invocation. It is also responsible for
choosing whether to proceed to the join point or to shortcut the advised method
execution by returning its own return value or throwing an exception
Spring Web Module
• Builds on top of the application context module
providing contexts for Web-based applications.
• Supports integration with Jakarta Struts via 2
options:
1. Configure Spring to manage your Actions as
beans using the ContextLoaderPlugin and set
their dependencies in a Spring context file.
2. Subclass Spring's ActionSupport classes and grab
your Spring-managed beans explicitly using
a getWebApplicationContext() method.
Spring MVC
• The Model-View-Controller (MVC) framework
is a full-featured MVC implementation for
building Web applications.
• The MVC framework is highly configurable via
strategy interfaces and accommodates
numerous view technologies including JSP,
Velocity and Tiles.

More Related Content

What's hot

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
 
Session 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOPSession 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOPPawanMM
 
Session 41 - Struts 2 Introduction
Session 41 - Struts 2 IntroductionSession 41 - Struts 2 Introduction
Session 41 - Struts 2 IntroductionPawanMM
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring FrameworkASG
 
Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCFunnelll
 
Introduction to Ibatis by Rohit
Introduction to Ibatis by RohitIntroduction to Ibatis by Rohit
Introduction to Ibatis by RohitRohit Prabhakar
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - CoreDzmitry Naskou
 
Most Useful Design Patterns
Most Useful Design PatternsMost Useful Design Patterns
Most Useful Design PatternsSteven Smith
 
Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts weili_at_slideshare
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework tola99
 
Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Sam Brannen
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction Hitesh-Java
 
Session 38 - Core Java (New Features) - Part 1
Session 38 - Core Java (New Features) - Part 1Session 38 - Core Java (New Features) - Part 1
Session 38 - Core Java (New Features) - Part 1PawanMM
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring FrameworkRaveendra R
 

What's hot (19)

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
 
Session 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOPSession 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOP
 
Session 41 - Struts 2 Introduction
Session 41 - Struts 2 IntroductionSession 41 - Struts 2 Introduction
Session 41 - Struts 2 Introduction
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoC
 
Java Concurrent
Java ConcurrentJava Concurrent
Java Concurrent
 
Introduction to Ibatis by Rohit
Introduction to Ibatis by RohitIntroduction to Ibatis by Rohit
Introduction to Ibatis by Rohit
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Maven
MavenMaven
Maven
 
Most Useful Design Patterns
Most Useful Design PatternsMost Useful Design Patterns
Most Useful Design Patterns
 
Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction
 
Session 38 - Core Java (New Features) - Part 1
Session 38 - Core Java (New Features) - Part 1Session 38 - Core Java (New Features) - Part 1
Session 38 - Core Java (New Features) - Part 1
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring User Guide
Spring User GuideSpring User Guide
Spring User Guide
 
Spring Framework Training Course
Spring Framework Training Course Spring Framework Training Course
Spring Framework Training Course
 

Similar to Introduction to Spring

Spring 1 day program
Spring 1 day programSpring 1 day program
Spring 1 day programMohit Kanwar
 
1. Spring intro IoC
1. Spring intro IoC1. Spring intro IoC
1. Spring intro IoCASG
 
Introduction to j2 ee frameworks
Introduction to j2 ee frameworksIntroduction to j2 ee frameworks
Introduction to j2 ee frameworksMukesh Kumar
 
Spring intro classes-in-mumbai
Spring intro classes-in-mumbaiSpring intro classes-in-mumbai
Spring intro classes-in-mumbaivibrantuser
 
Spring Framework Presantation Part 1-Core
Spring Framework Presantation Part 1-CoreSpring Framework Presantation Part 1-Core
Spring Framework Presantation Part 1-CoreDonald Lika
 
.net Based Component Technologies
.net Based Component Technologies.net Based Component Technologies
.net Based Component Technologiesprakashk453625
 
Spring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggetsSpring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggetsVirtual Nuggets
 
AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)Igor Talevski
 
Framework adoption for java enterprise application development
Framework adoption for java enterprise application developmentFramework adoption for java enterprise application development
Framework adoption for java enterprise application developmentClarence Ho
 
스프링 프레임워크
스프링 프레임워크스프링 프레임워크
스프링 프레임워크Yoonki Chang
 

Similar to Introduction to Spring (20)

Spring framework
Spring frameworkSpring framework
Spring framework
 
Introduction to Spring & Spring BootFramework
Introduction to Spring  & Spring BootFrameworkIntroduction to Spring  & Spring BootFramework
Introduction to Spring & Spring BootFramework
 
Hybernat and structs, spring classes in mumbai
Hybernat and structs, spring classes in mumbaiHybernat and structs, spring classes in mumbai
Hybernat and structs, spring classes in mumbai
 
Java Spring
Java SpringJava Spring
Java Spring
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring 1 day program
Spring 1 day programSpring 1 day program
Spring 1 day program
 
Spring session
Spring sessionSpring session
Spring session
 
1. Spring intro IoC
1. Spring intro IoC1. Spring intro IoC
1. Spring intro IoC
 
Introduction to j2 ee frameworks
Introduction to j2 ee frameworksIntroduction to j2 ee frameworks
Introduction to j2 ee frameworks
 
Spring
SpringSpring
Spring
 
Spring intro classes-in-mumbai
Spring intro classes-in-mumbaiSpring intro classes-in-mumbai
Spring intro classes-in-mumbai
 
Spring
SpringSpring
Spring
 
spring
springspring
spring
 
Spring Framework Presantation Part 1-Core
Spring Framework Presantation Part 1-CoreSpring Framework Presantation Part 1-Core
Spring Framework Presantation Part 1-Core
 
.net Based Component Technologies
.net Based Component Technologies.net Based Component Technologies
.net Based Component Technologies
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggetsSpring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggets
 
AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)
 
Framework adoption for java enterprise application development
Framework adoption for java enterprise application developmentFramework adoption for java enterprise application development
Framework adoption for java enterprise application development
 
스프링 프레임워크
스프링 프레임워크스프링 프레임워크
스프링 프레임워크
 

More from Sujit Kumar

Introduction to OOP with java
Introduction to OOP with javaIntroduction to OOP with java
Introduction to OOP with javaSujit Kumar
 
SFDC Database Basics
SFDC Database BasicsSFDC Database Basics
SFDC Database BasicsSujit Kumar
 
SFDC Database Security
SFDC Database SecuritySFDC Database Security
SFDC Database SecuritySujit Kumar
 
SFDC Social Applications
SFDC Social ApplicationsSFDC Social Applications
SFDC Social ApplicationsSujit Kumar
 
SFDC Other Platform Features
SFDC Other Platform FeaturesSFDC Other Platform Features
SFDC Other Platform FeaturesSujit Kumar
 
SFDC Outbound Integrations
SFDC Outbound IntegrationsSFDC Outbound Integrations
SFDC Outbound IntegrationsSujit Kumar
 
SFDC Inbound Integrations
SFDC Inbound IntegrationsSFDC Inbound Integrations
SFDC Inbound IntegrationsSujit Kumar
 
SFDC UI - Advanced Visualforce
SFDC UI - Advanced VisualforceSFDC UI - Advanced Visualforce
SFDC UI - Advanced VisualforceSujit Kumar
 
SFDC UI - Introduction to Visualforce
SFDC UI -  Introduction to VisualforceSFDC UI -  Introduction to Visualforce
SFDC UI - Introduction to VisualforceSujit Kumar
 
SFDC Deployments
SFDC DeploymentsSFDC Deployments
SFDC DeploymentsSujit Kumar
 
SFDC Data Loader
SFDC Data LoaderSFDC Data Loader
SFDC Data LoaderSujit Kumar
 
SFDC Advanced Apex
SFDC Advanced Apex SFDC Advanced Apex
SFDC Advanced Apex Sujit Kumar
 
SFDC Introduction to Apex
SFDC Introduction to ApexSFDC Introduction to Apex
SFDC Introduction to ApexSujit Kumar
 
SFDC Database Additional Features
SFDC Database Additional FeaturesSFDC Database Additional Features
SFDC Database Additional FeaturesSujit Kumar
 
Introduction to SalesForce
Introduction to SalesForceIntroduction to SalesForce
Introduction to SalesForceSujit Kumar
 
More about java strings - Immutability and String Pool
More about java strings - Immutability and String PoolMore about java strings - Immutability and String Pool
More about java strings - Immutability and String PoolSujit Kumar
 
Hibernate First and Second level caches
Hibernate First and Second level cachesHibernate First and Second level caches
Hibernate First and Second level cachesSujit Kumar
 
Java equals hashCode Contract
Java equals hashCode ContractJava equals hashCode Contract
Java equals hashCode ContractSujit Kumar
 
Java Comparable and Comparator
Java Comparable and ComparatorJava Comparable and Comparator
Java Comparable and ComparatorSujit Kumar
 

More from Sujit Kumar (20)

Introduction to OOP with java
Introduction to OOP with javaIntroduction to OOP with java
Introduction to OOP with java
 
SFDC Database Basics
SFDC Database BasicsSFDC Database Basics
SFDC Database Basics
 
SFDC Database Security
SFDC Database SecuritySFDC Database Security
SFDC Database Security
 
SFDC Social Applications
SFDC Social ApplicationsSFDC Social Applications
SFDC Social Applications
 
SFDC Other Platform Features
SFDC Other Platform FeaturesSFDC Other Platform Features
SFDC Other Platform Features
 
SFDC Outbound Integrations
SFDC Outbound IntegrationsSFDC Outbound Integrations
SFDC Outbound Integrations
 
SFDC Inbound Integrations
SFDC Inbound IntegrationsSFDC Inbound Integrations
SFDC Inbound Integrations
 
SFDC UI - Advanced Visualforce
SFDC UI - Advanced VisualforceSFDC UI - Advanced Visualforce
SFDC UI - Advanced Visualforce
 
SFDC UI - Introduction to Visualforce
SFDC UI -  Introduction to VisualforceSFDC UI -  Introduction to Visualforce
SFDC UI - Introduction to Visualforce
 
SFDC Deployments
SFDC DeploymentsSFDC Deployments
SFDC Deployments
 
SFDC Batch Apex
SFDC Batch ApexSFDC Batch Apex
SFDC Batch Apex
 
SFDC Data Loader
SFDC Data LoaderSFDC Data Loader
SFDC Data Loader
 
SFDC Advanced Apex
SFDC Advanced Apex SFDC Advanced Apex
SFDC Advanced Apex
 
SFDC Introduction to Apex
SFDC Introduction to ApexSFDC Introduction to Apex
SFDC Introduction to Apex
 
SFDC Database Additional Features
SFDC Database Additional FeaturesSFDC Database Additional Features
SFDC Database Additional Features
 
Introduction to SalesForce
Introduction to SalesForceIntroduction to SalesForce
Introduction to SalesForce
 
More about java strings - Immutability and String Pool
More about java strings - Immutability and String PoolMore about java strings - Immutability and String Pool
More about java strings - Immutability and String Pool
 
Hibernate First and Second level caches
Hibernate First and Second level cachesHibernate First and Second level caches
Hibernate First and Second level caches
 
Java equals hashCode Contract
Java equals hashCode ContractJava equals hashCode Contract
Java equals hashCode Contract
 
Java Comparable and Comparator
Java Comparable and ComparatorJava Comparable and Comparator
Java Comparable and Comparator
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 

Introduction to Spring

  • 2. Dependency Injection (IOC) • Do not create your objects but describe how they should be created. • You don't directly connect your components and services together in code but describe how they are wired together in a configuration file. • A container (in the case of the Spring framework, the IOC container) is then responsible for hooking it all up.
  • 3. Types of Dependency injection • Constructor Injection => Dependencies are provided as constructor parameters. • Setter Injection => Dependencies are assigned through JavaBeans properties (ex: setter methods).
  • 4. Benefits of Spring • Minimizes the amount of code in your application. • Make your application more testable. IOC containers make unit testing and switching implementations very easy by manually allowing you to inject your own objects into the object under test. • Loose coupling is promoted. • IOC containers support eager instantiation and lazy loading of services. • Use whatever modules you need, leave what you don’t need. • Enables POJO programming without any dependencies on an Application Server like Tomcat or WebLogic.
  • 5. Features of Spring • Lightweight:: spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 1MB. And the processing overhead is also very negligible. • Inversion of control (IOC): Loose coupling is achieved in spring using the technique Inversion of Control. The objects give their dependencies instead of creating or looking for dependent objects. • Aspect oriented (AOP): Spring supports Aspect oriented programming and enables cohesive development by separating application business logic from system services. • Container: Spring contains and manages the life cycle and configuration of application objects. • MVC Framework: Highly configurable and accommodates multiple view technologies like JSP, Velocity and Tiles. • Transaction Management: Generic abstraction layer for transaction management with pluggable transaction managers. Not tied to J2EE environments and it can be also used in container less environments. • JDBC Exception Handling: The JDBC abstraction layer of the Spring offers a meaningful exception hierarchy, which simplifies the error handling strategy. Integration with Hibernate, JDO, and iBATIS.
  • 6. 7 Modules of Spring • The core container: Bean Factory, Application Context, IOC/DI. • Spring context: Configuration file that provides context information to the Spring framework. Includes enterprise services such as JNDI, JMS, e-mail, internalization, validation and scheduling functionality. • Spring AOP: Most important uses are transaction management, security , logging, performance metrics gathering. • Spring DAO: meaningful exception hierarchy for managing the exception handling and error messages thrown by different database vendors. • Spring ORM: JDO, Hibernate and iBatis . All of these comply to Spring's generic transaction and DAO exception hierarchies.. • Spring Web module: The Web context module builds on top of the application context module, providing contexts for Web-based applications. • Spring MVC framework: The Model-View-Controller (MVC) framework is a full-featured MVC implementation for building Web applications.
  • 7. Bean Factory • Like a factory class that contains a collection of beans. Holds bean definitions of multiple beans within itself and then instantiates the bean whenever asked for by clients. • Can create associations between collaborating objects as they are instantiated. This removes the burden of configuration from bean itself and the beans client. • Manage the life cycle of a bean making calls to custom initialization and destruction methods.
  • 8. Bean Scopes in Spring • singleton => single object instance per Spring IoC container. • prototype => new object instance whenever requested. • request => lifecycle of a single HTTP request • session => lifecycle of a HTTP Session. • global session => 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.
  • 9. Application Context • An Application Context is same as a bean factory. Both load bean definitions, wire beans together and dispense beans upon request. • However, an Application Context is a more advanced container and has a lot more functionality: • It provides a means for resolving text messages, including support for internationalization. • It provides a generic way to load file resources. • It can publish events to beans that are registered as listeners.
  • 10. Common Implementations of the Application Context • ClassPathXmlApplicationContext : loads context definition from an XML file located in the classpath, treating context definitions as classpath resources. ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml"); • FileSystemXmlApplicationContext : loads context definition from an XML file in the file system. ApplicationContext context = new FileSystemXmlApplicationContext("bean.xml"); • XmlWebApplicationContext : It loads context definition from an XML file contained within a web application.
  • 11. Typical Spring Application • An interface class containing abstract methods. • One or more implementation classes that implement the above interface with properties & their setter and getter methods, method implementations of the interface that it implements. • An XML file called Spring configuration file. • Client program that uses the interface methods.
  • 12. Spring JDBC • Spring's JdbcTemplate is central class to interact with a database through JDBC. • Provides many convenience methods like: 1. Convert database data into primitives or objects 2. Execute prepared and callable statements 3. Custom database error handling.
  • 13. ORMs supported by Spring • • • • Hibernate iBatis JPA (Java Persistence API) JDO (Java Data Objects)
  • 14. Access Hibernate using Spring Two Options: 1. Inversion of Control with HibernateTemplate. 2. Extending HibernateDaoSupport and applying an AOP Interceptor.
  • 15. Spring Transaction Management • Declarative transaction management => good idea only if you have a large number of transactional operations. It is non-invasive - keeps transaction management code out of business logic and is not difficult to configure. • Programmatic transaction management => good idea only if you have a small number of transactional operations.
  • 16. Spring AOP • Modularize crosscutting concerns such as transaction management, security, logging and gathering performance metrics. • The core construct of AOP is the aspect which encapsulates behaviors affecting multiple classes into reusable modules.
  • 17. AOP Terms • Aspect: A modularization of a concern that cuts across multiple objects. Transaction management is a good example of a crosscutting concern in J2EE applications. • Join Point : A point during the execution of a program, such as the execution of a method or the handling of an exception. In Spring AOP, a join point always represents a method execution. • Pointcut: A predicate that matches join points. Advice is associated with a pointcut expression and runs at any join point matched by the pointcut (for example, the execution of a method with a certain name). • Advice: action taken by an aspect at a particular join point. Different types of advice include "around," "before" and "after" advice. Model an advice as an interceptor, maintaining a chain of interceptors "around" the join point.
  • 18. AOP Terms (contd…) • Target object: Object being advised by one or more aspects. Also referred to as the advised object. Since Spring AOP is implemented using runtime proxies, this object will always be a proxied object. • AOP proxy: An object created by the AOP framework in order to implement the aspect contracts (advise method executions and so on). In the Spring Framework, an AOP proxy will be a JDK dynamic proxy or a CGLIB proxy. Proxy creation is transparent to users of the schema-based and @AspectJ styles of aspect declaration introduced in Spring 2.0. • Weaving: Linking aspects with other application types or objects to create an advised object. This can be done at compile time (using the AspectJ compiler, for example), load time, or at runtime. Spring AOP, like other pure Java AOP frameworks, performs weaving at runtime.
  • 19. Types of Advice • Before advice: Advice that executes before a join point, but which does not have the ability to prevent execution flow proceeding to the join point (unless it throws an exception). • After returning advice: Advice to be executed after a join point completes normally: for example, if a method returns without throwing an exception. • After throwing advice: Advice to be executed if a method exits by throwing an exception. • After (finally) advice: Advice to be executed regardless of the means by which a join point exits (normal or exceptional return). • Around advice: Advice that surrounds a join point such as a method invocation. This is the most powerful kind of advice. Around advice can perform custom behavior before and after the method invocation. It is also responsible for choosing whether to proceed to the join point or to shortcut the advised method execution by returning its own return value or throwing an exception
  • 20. Spring Web Module • Builds on top of the application context module providing contexts for Web-based applications. • Supports integration with Jakarta Struts via 2 options: 1. Configure Spring to manage your Actions as beans using the ContextLoaderPlugin and set their dependencies in a Spring context file. 2. Subclass Spring's ActionSupport classes and grab your Spring-managed beans explicitly using a getWebApplicationContext() method.
  • 21. Spring MVC • The Model-View-Controller (MVC) framework is a full-featured MVC implementation for building Web applications. • The MVC framework is highly configurable via strategy interfaces and accommodates numerous view technologies including JSP, Velocity and Tiles.