SlideShare a Scribd company logo
Workshop of Spring Application Framework at Capegemini




                                        Presented By
                                      Rajkumar Singh


                                 www.rajkrrsingh.blogspot.com
Agenda

Introduction
Spring Architecture
Spring Beans
Spring IOC
Setting up Spring Environment
Beans Life cycles
Spring DAO
Spring ORM
Spring AOP
Q&A




                                 www.rajkrrsingh.blogspot.com
Introduction
Spring framework was initially written by Rod Johnson and
was first released under the Apache 2.0 license in June
2003.

Primary purpose is to reduce the dependencies(loose
couple)

Spring deliver many significant benefits to the developers
reducing development effort and cost while improving test
coverage and quality

Handle the infrastructure so that developer can focus on
the development only

Enables you to build application from POJOs

Spring does not recreate all the framework but make use of
the existing one like ORM,logging,JEE framework.
                                    www.rajkrrsingh.blogspot.com
What Spring Offers


Dependency Injection

Aspect Oriented Programming (AOP)

Portable Serives
  ORM
  DAO
  MVC




                               www.rajkrrsingh.blogspot.com
Application Layering


Presentation Layer
   Spring MVC
   Spring Web Service Layer
                      Gateway to expose business logic to the outside world

Persistence Layer    Not well defined in many applications today or tightly
                      coupled in an inappropriate layer.
  JDBC
  ORM                Manages ‘container level services’ Eg. transactions,
                      security, data access logic, and manipulates domain objects

Domain Layer
  POJOs



                                         www.rajkrrsingh.blogspot.com
Spring Architecture




                      www.rajkrrsingh.blogspot.com
Spring Architecture



Core & Beans:
Provides fundamental functionality & Dependency Injection features.
Primary component is the BeanFactory (Factory pattern )

The Context module
Builds on the base modules.
Access objects in a framework-style manner similar to a JNDI registry.
Also supports Java EE features such as EJB, JMX ,and basic remoting.
The ApplicationContext interface is the focal point of the module.

The Expression Language module
Provides a powerful expression language for querying and
manipulating an object graph at runtime.

                                           www.rajkrrsingh.blogspot.com
Spring Architecture
The JDBC module
a JDBC-abstraction layer that removes tedious
JDBC coding, parsing of database-vendor specific error codes.
The ORM module
integration layers for ORM APIs, including JPA, JDO, Hibernate, & iBatis.

The OXM module supports
Object/XML mapping implementations for JAXB, Castor, XMLBeans, JiBX and X

The JMS Module
contains features for producing and consuming messages.


 The Transaction module supports
 programmatic and declarative transaction management



                                             www.rajkrrsingh.blogspot.com
Spring Architecture
Spring's Web module
provides basic web-oriented integration features
(multipart file-upload)
initialization of the IoC container using servlet listeners
Web Servlet
Spring's model-view-controller (MVC)



The Web-Struts module
contains Support classes for integrating a classic Struts web tier within
 a Spring application.


The Web-Portlet module
provides the MVC implementation to be used in a portlet environment



                                                 www.rajkrrsingh.blogspot.com
Spring IOC
Inversion of control is all about Object Dependencies

Traditional Object Creation Approach
         Direct Object Creation  new Employee()
         FactoryImplementation   EmpFactory().getEmp()
         JNDI Services           naming.lookup()

Spring Approach

Spring Container creates all the objects,
wires them together by setting the necessary
properties, and determines when methods will
be invoked.




                                           www.rajkrrsingh.blogspot.com
Spring Container
Fundamental part of the framework.
Two packages provides the basis for the Spring Framework's IoC container.
– org.springframework.beans
– org.springframework.context

BeanFactory provides the configuration framework and basic functionality,
and the ApplicationContext adds more enterprise-specific functionality.

The org.springframework.beans.factory.BeanFactory is the actual representati
the Spring IoC container

Responsible for containing and managing beans.

The most commonly used BeanFactory implementation is the XmlBeanFactor

The XmlBeanFactory takes XML configuration metadata and uses it to create
configured system or application.


                                            www.rajkrrsingh.blogspot.com
Spring Container

The interface org.springframework.context.ApplicationContext represents the
Spring IoC container and is responsible for instantiating, configuring, and
assembling the beans.

The container gets its instructions by reading configuration metadata.

The configuration metadata is represented in XML and Java annotations

Several implementations of the ApplicationContext interface are supplied
 with Spring.

In standalone applications it is common to create an instance of
ClassPathXmlApplicationContext or FileSystemXmlApplicationContext




                                             www.rajkrrsingh.blogspot.com
Ways To Initialize Spring Container




                        www.rajkrrsingh.blogspot.com
Type of Dependency Injection

 Setter method Injection

 Constructor Injection

 Configuration File Injection




                                 www.rajkrrsingh.blogspot.com
Examples for dependency Injection
Setup Enviornment for Spring


Install JAVA
If you are running Windows and installed the JDK in C:jdk1.6.0_15, you would have to
put the following line in your C:autoexec.bat file.
set PATH=C:jdk1.6.0_15bin;%PATH%
set JAVA_HOME=C:jdk1.6.0_15


Unix (Solaris, Linux, etc.), if the SDK is installed in /usr/local/jdk1.6.0_15 and you use the
C shell, you would put the following into your .cshrc file.
setenv PATH /usr/local/jdk1.6.0_15/bin:$PATH
 setenv JAVA_HOME /usr/local/jdk1.6.0_15

Download Spring Jars

Install Common Logging
Download Apache Commons Logging API from http://commons.apache.org/logging

Install Eclipse and setup for Spring


                                                       www.rajkrrsingh.blogspot.com
Reference to Other Beans (DI)




                       www.rajkrrsingh.blogspot.com
Some More Example
Alias

Import




Initialize bean static Bean Factory Method
         <bean id="mp3ply" class="com.test.Mp3Player" factory-method="factoryMethod">

         </bean>

         public Class Mp3Player{
         private static Mp3Player mp3ply = new Mp3Player();
         public Mp3Player(){}

         public static Mp3Player factoryMethod(){
         return mp3ply;
         }
         }


                                                              www.rajkrrsingh.blogspot.com
Some More Example

Collections

Inner Beans

Autowire

Namespaces

Depends Upon

ApplicationContextAware interface

BeanNameAware interface

InitializingBean interface



                                     www.rajkrrsingh.blogspot.com
Beans Scopes

Scope            Description

                 This scopes the bean definition to a single instance per
singleton
                 Spring IoC container (default).

                 This scopes a single bean definition to have any number of
prototype
                 object instances.
                 This scopes a bean definition to an HTTP request. Only
request          valid in the context of a web-aware Spring
                 ApplicationContext.
                 This scopes a bean definition to an HTTP session. Only
session          valid in the context of a web-aware Spring
                 ApplicationContext.
                 This scopes a bean definition to a global HTTP session.
global-session   Only valid in the context of a web-aware Spring
                 ApplicationContext.




                                              www.rajkrrsingh.blogspot.com
Beans Life Cycle
 When a bean is instantiated, it may be required to perform some initializatio
to get it into a usable state

When the bean is no longer required and is removed from the container,
some cleanup may be required.

Register the shutdown hook for the ApplicationContext

Callback Methods: Init and destroy methods
   The init-method attribute specifies a method that is to be called
        on the bean immediately upon instantiation
   destroy-method specifies a method that is called just before a bean
        is removed from the container.




                                            www.rajkrrsingh.blogspot.com
Beans Post Processors
 The BeanPostProcessor interface defines callback methods that you can
  implement to provide your own instantiation logic

You can also implement some custom logic after the Spring container finishe
  instantiating, configuring, and initializing a bean by impl PostProcessors

You can have multiple Bean Post processor and can define their order of
  execution

ApplicationContext automatically detects any bean as a post processor who
implements BeanPostProcessor Interface




                                          www.rajkrrsingh.blogspot.com
Aspect Oriented Programming(AOP)

   ObjectA                                 ObjectC
                                           methodA()
   methodA()
                                           .
   .
                                           .
   .
                                           methodN()
   methodN()v
                Logging      Security


                 Aspect Configuration
   ObjectB                                  ObjectD
   methodA()                                methodA()
   .                                        .
   .                                        .
   methodN()                                methodN()




                                  www.rajkrrsingh.blogspot.com
Aspect Oriented Programming(AOP)
Complements OO programming

Aspect Oriented Programming entails breaking down program logic into dist
 parts called so-called concerns

Cross-cutting concerns are conceptually separate from the application's
 business logic, e.g. ogging, auditing, declarative transactions, security, and
 caching etc

Spring AOP module provides interceptors to intercept an application,
 for example, when a method is executed, you can add extra functionality
 before or after the method execution.




                                            www.rajkrrsingh.blogspot.com
Aspect Oriented Programming(AOP)
Components of AOP
   Aspect – unit of modularity for crosscutting concerns

   Join point – well-defined points in the program flow

   Pointcut – join point queries where advice executes

   Advice – the block of code that runs based on the pointcut definition

   Weaving – can be done at runtime or compile time.
   Inserts the advice (crosscutting concerns) into the code (core concerns).




                                          www.rajkrrsingh.blogspot.com
Setting up AOP Environment in Eclipse
AOP Dependencies
   AspectJ: http://www.eclipse.org/aspectj/downloads.php
   AOP Alliance: http://aopalliance.sourceforge.net/
   CGILIB: http://cglib.sourceforge.net/
   Spring 3 ASM: http://asm.ow2.org/



   Examples…..




                                     www.rajkrrsingh.blogspot.com
Spring DAO and ORM
 Built in code templates that support JDBC, Hibernate, JDO,
and iBatis SQL Maps

Simplifies data access coding by reducing redundant code and
helps avoid common errors.

 Alleviates opening and closing connections in your DAO code.

No more ThreadLocal or passing Connection/Session objects.

Transaction management is handled by a wired bean

You are dropped into the template with the resources you need
for data access – Session, PreparedStatement, etc.

Optional separate JDBC framework

                                     www.rajkrrsingh.blogspot.com
JdbcTemplate
Central class in the JDBC core package

Handles the creation and release of resources.

Executes the core JDBC workflow like statement creation
and
Execution

 Executes
       – SQL queries
       – update statements
       – stored procedure calls
       – iteration over ResultSets
       – extraction of returned parameter values.

Also catches JDBC exceptions

                                      www.rajkrrsingh.blogspot.com
DataSource Configuration




                      www.rajkrrsingh.blogspot.com
Spring ORM : Working with Hibernate




                      www.rajkrrsingh.blogspot.com
Spring ORM : Working with Hibernate




                      www.rajkrrsingh.blogspot.com
Q&A




      www.rajkrrsingh.blogspot.com
Thanks


if you have any query concerns
            write to me
                 on
     rajkrrsingh@gmail.com




                    www.rajkrrsingh.blogspot.com

More Related Content

What's hot

Spring Data JPA
Spring Data JPASpring Data JPA
Spring Data JPA
Knoldus Inc.
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
Rasheed Waraich
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Hùng Nguyễn Huy
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
tola99
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
Jonathan Holloway
 
jpa-hibernate-presentation
jpa-hibernate-presentationjpa-hibernate-presentation
jpa-hibernate-presentation
John Slick
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
Dzmitry Naskou
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
elliando dias
 
Spring Boot
Spring BootSpring Boot
Spring Boot
HongSeong Jeon
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
Guo Albert
 
Spring User Guide
Spring User GuideSpring User Guide
Spring User Guide
Muthuselvam RS
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
Dzmitry Naskou
 
Spring core module
Spring core moduleSpring core module
Spring core module
Raj Tomar
 
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
Funnelll
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
Manav Prasad
 
Spring boot
Spring bootSpring boot
Spring boot
sdeeg
 
Spring boot jpa
Spring boot jpaSpring boot jpa
Spring boot jpa
Hamid Ghorbani
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Serhat Can
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
guest11106b
 
Java Spring
Java SpringJava Spring
Java Spring
AathikaJava
 

What's hot (20)

Spring Data JPA
Spring Data JPASpring Data JPA
Spring Data JPA
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 
jpa-hibernate-presentation
jpa-hibernate-presentationjpa-hibernate-presentation
jpa-hibernate-presentation
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
 
Spring User Guide
Spring User GuideSpring User Guide
Spring User Guide
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
 
Spring core module
Spring core moduleSpring core module
Spring core module
 
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
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring boot jpa
Spring boot jpaSpring boot jpa
Spring boot jpa
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Java Spring
Java SpringJava Spring
Java Spring
 

Viewers also liked

Promotion of a company
Promotion of a companyPromotion of a company
Promotion of a company
Saji Thomas
 
Spring orm notes_by_soma_sekhar_reddy_javabynataraj
Spring orm notes_by_soma_sekhar_reddy_javabynatarajSpring orm notes_by_soma_sekhar_reddy_javabynataraj
Spring orm notes_by_soma_sekhar_reddy_javabynataraj
Satya Johnny
 
JSR 168 Portal - Overview
JSR 168 Portal - OverviewJSR 168 Portal - Overview
JSR 168 Portal - Overview
Vinay Kumar
 
Spring framework part 2
Spring framework  part 2Spring framework  part 2
Spring framework part 2
Skillwise Group
 
Incorporation of Company in India
Incorporation of Company in IndiaIncorporation of Company in India
Incorporation of Company in India
Ritambhara Agrawal
 
Steps for Incorporation of a Company in India
Steps for Incorporation of a Company in IndiaSteps for Incorporation of a Company in India
Steps for Incorporation of a Company in India
Rayvat Accounting
 
Incorporation of companies
Incorporation of companiesIncorporation of companies
Incorporation of companies
Altacit Global
 
Incorporation Powerpoint
Incorporation PowerpointIncorporation Powerpoint
Incorporation Powerpoint
markklein57
 
Getting Started with Spring Framework
Getting Started with Spring FrameworkGetting Started with Spring Framework
Getting Started with Spring Framework
Edureka!
 
incorporation of company
 incorporation of company incorporation of company
incorporation of company
Accuprosys
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Dineesha Suraweera
 
Incorporation of company in india
Incorporation of company in indiaIncorporation of company in india
Incorporation of company in india
mschhajedmarkting
 
1 promotion & incorporation of a company
1 promotion & incorporation of a company1 promotion & incorporation of a company
1 promotion & incorporation of a company
Ramandeep Sidhu
 
Ppt on incorporation of company as per new company act, 2013 (updated)
Ppt on incorporation of company as per new company act, 2013 (updated)Ppt on incorporation of company as per new company act, 2013 (updated)
Ppt on incorporation of company as per new company act, 2013 (updated)
Sandeep Kumar
 
Formation of companies
Formation of companiesFormation of companies
Formation of companies
Nitin Patil
 
Promotion
PromotionPromotion
Promotion
Sonu Verma
 
Formation of a company
Formation of a companyFormation of a company
Formation of a company
guptakanika16
 
Support JEE Spring Inversion de Controle IOC et Spring MVC
Support JEE Spring Inversion de Controle IOC et Spring MVCSupport JEE Spring Inversion de Controle IOC et Spring MVC
Support JEE Spring Inversion de Controle IOC et Spring MVC
ENSET, Université Hassan II Casablanca
 

Viewers also liked (18)

Promotion of a company
Promotion of a companyPromotion of a company
Promotion of a company
 
Spring orm notes_by_soma_sekhar_reddy_javabynataraj
Spring orm notes_by_soma_sekhar_reddy_javabynatarajSpring orm notes_by_soma_sekhar_reddy_javabynataraj
Spring orm notes_by_soma_sekhar_reddy_javabynataraj
 
JSR 168 Portal - Overview
JSR 168 Portal - OverviewJSR 168 Portal - Overview
JSR 168 Portal - Overview
 
Spring framework part 2
Spring framework  part 2Spring framework  part 2
Spring framework part 2
 
Incorporation of Company in India
Incorporation of Company in IndiaIncorporation of Company in India
Incorporation of Company in India
 
Steps for Incorporation of a Company in India
Steps for Incorporation of a Company in IndiaSteps for Incorporation of a Company in India
Steps for Incorporation of a Company in India
 
Incorporation of companies
Incorporation of companiesIncorporation of companies
Incorporation of companies
 
Incorporation Powerpoint
Incorporation PowerpointIncorporation Powerpoint
Incorporation Powerpoint
 
Getting Started with Spring Framework
Getting Started with Spring FrameworkGetting Started with Spring Framework
Getting Started with Spring Framework
 
incorporation of company
 incorporation of company incorporation of company
incorporation of company
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Incorporation of company in india
Incorporation of company in indiaIncorporation of company in india
Incorporation of company in india
 
1 promotion & incorporation of a company
1 promotion & incorporation of a company1 promotion & incorporation of a company
1 promotion & incorporation of a company
 
Ppt on incorporation of company as per new company act, 2013 (updated)
Ppt on incorporation of company as per new company act, 2013 (updated)Ppt on incorporation of company as per new company act, 2013 (updated)
Ppt on incorporation of company as per new company act, 2013 (updated)
 
Formation of companies
Formation of companiesFormation of companies
Formation of companies
 
Promotion
PromotionPromotion
Promotion
 
Formation of a company
Formation of a companyFormation of a company
Formation of a company
 
Support JEE Spring Inversion de Controle IOC et Spring MVC
Support JEE Spring Inversion de Controle IOC et Spring MVCSupport JEE Spring Inversion de Controle IOC et Spring MVC
Support JEE Spring Inversion de Controle IOC et Spring MVC
 

Similar to Spring framework

Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Arjun Thakur
 
Spring Basics
Spring BasicsSpring Basics
Signal Framework
Signal FrameworkSignal Framework
Signal Framework
Aurora Softworks
 
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
 
Spring IOC and DAO
Spring IOC and DAOSpring IOC and DAO
Spring IOC and DAO
AnushaNaidu
 
Spring (1)
Spring (1)Spring (1)
Spring (1)
Aneega
 
Spring Fa Qs
Spring Fa QsSpring Fa Qs
Spring Fa Qs
jbashask
 
Spring framework
Spring frameworkSpring framework
Spring framework
Sonal Poddar
 
Spring training
Spring trainingSpring training
Spring training
shah_d_p
 
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
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
Dhaval Shah
 
Introduction to Spring sec1.pptx
Introduction to Spring sec1.pptxIntroduction to Spring sec1.pptx
Introduction to Spring sec1.pptx
NourhanTarek23
 
Session 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI BeansSession 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI Beans
PawanMM
 
Java spring ppt
Java spring pptJava spring ppt
Java spring ppt
natashasweety7
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
Hamid Ghorbani
 
Spring
SpringSpring
Spring 2
Spring 2Spring 2
Spring 2
Aruvi Thottlan
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
hchen1
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Raveendra R
 

Similar to Spring framework (20)

Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
 
Signal Framework
Signal FrameworkSignal Framework
Signal Framework
 
Java J2EE Interview Question Part 2
Java J2EE Interview Question Part 2Java J2EE Interview Question Part 2
Java J2EE Interview Question Part 2
 
Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2
 
Spring IOC and DAO
Spring IOC and DAOSpring IOC and DAO
Spring IOC and DAO
 
Spring (1)
Spring (1)Spring (1)
Spring (1)
 
Spring Fa Qs
Spring Fa QsSpring Fa Qs
Spring Fa Qs
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring training
Spring trainingSpring training
Spring training
 
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 Basics
Spring BasicsSpring Basics
Spring Basics
 
Introduction to Spring sec1.pptx
Introduction to Spring sec1.pptxIntroduction to Spring sec1.pptx
Introduction to Spring sec1.pptx
 
Session 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI BeansSession 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI Beans
 
Java spring ppt
Java spring pptJava spring ppt
Java spring ppt
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Spring
SpringSpring
Spring
 
Spring 2
Spring 2Spring 2
Spring 2
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 

Recently uploaded

Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 

Recently uploaded (20)

Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 

Spring framework

  • 1. Workshop of Spring Application Framework at Capegemini Presented By Rajkumar Singh www.rajkrrsingh.blogspot.com
  • 2. Agenda Introduction Spring Architecture Spring Beans Spring IOC Setting up Spring Environment Beans Life cycles Spring DAO Spring ORM Spring AOP Q&A www.rajkrrsingh.blogspot.com
  • 3. Introduction Spring framework was initially written by Rod Johnson and was first released under the Apache 2.0 license in June 2003. Primary purpose is to reduce the dependencies(loose couple) Spring deliver many significant benefits to the developers reducing development effort and cost while improving test coverage and quality Handle the infrastructure so that developer can focus on the development only Enables you to build application from POJOs Spring does not recreate all the framework but make use of the existing one like ORM,logging,JEE framework. www.rajkrrsingh.blogspot.com
  • 4. What Spring Offers Dependency Injection Aspect Oriented Programming (AOP) Portable Serives ORM DAO MVC www.rajkrrsingh.blogspot.com
  • 5. Application Layering Presentation Layer Spring MVC Spring Web Service Layer Gateway to expose business logic to the outside world Persistence Layer Not well defined in many applications today or tightly coupled in an inappropriate layer. JDBC ORM Manages ‘container level services’ Eg. transactions, security, data access logic, and manipulates domain objects Domain Layer POJOs www.rajkrrsingh.blogspot.com
  • 6. Spring Architecture www.rajkrrsingh.blogspot.com
  • 7. Spring Architecture Core & Beans: Provides fundamental functionality & Dependency Injection features. Primary component is the BeanFactory (Factory pattern ) The Context module Builds on the base modules. Access objects in a framework-style manner similar to a JNDI registry. Also supports Java EE features such as EJB, JMX ,and basic remoting. The ApplicationContext interface is the focal point of the module. The Expression Language module Provides a powerful expression language for querying and manipulating an object graph at runtime. www.rajkrrsingh.blogspot.com
  • 8. Spring Architecture The JDBC module a JDBC-abstraction layer that removes tedious JDBC coding, parsing of database-vendor specific error codes. The ORM module integration layers for ORM APIs, including JPA, JDO, Hibernate, & iBatis. The OXM module supports Object/XML mapping implementations for JAXB, Castor, XMLBeans, JiBX and X The JMS Module contains features for producing and consuming messages. The Transaction module supports programmatic and declarative transaction management www.rajkrrsingh.blogspot.com
  • 9. Spring Architecture Spring's Web module provides basic web-oriented integration features (multipart file-upload) initialization of the IoC container using servlet listeners Web Servlet Spring's model-view-controller (MVC) The Web-Struts module contains Support classes for integrating a classic Struts web tier within a Spring application. The Web-Portlet module provides the MVC implementation to be used in a portlet environment www.rajkrrsingh.blogspot.com
  • 10. Spring IOC Inversion of control is all about Object Dependencies Traditional Object Creation Approach Direct Object Creation new Employee() FactoryImplementation EmpFactory().getEmp() JNDI Services naming.lookup() Spring Approach Spring Container creates all the objects, wires them together by setting the necessary properties, and determines when methods will be invoked. www.rajkrrsingh.blogspot.com
  • 11. Spring Container Fundamental part of the framework. Two packages provides the basis for the Spring Framework's IoC container. – org.springframework.beans – org.springframework.context BeanFactory provides the configuration framework and basic functionality, and the ApplicationContext adds more enterprise-specific functionality. The org.springframework.beans.factory.BeanFactory is the actual representati the Spring IoC container Responsible for containing and managing beans. The most commonly used BeanFactory implementation is the XmlBeanFactor The XmlBeanFactory takes XML configuration metadata and uses it to create configured system or application. www.rajkrrsingh.blogspot.com
  • 12. Spring Container The interface org.springframework.context.ApplicationContext represents the Spring IoC container and is responsible for instantiating, configuring, and assembling the beans. The container gets its instructions by reading configuration metadata. The configuration metadata is represented in XML and Java annotations Several implementations of the ApplicationContext interface are supplied with Spring. In standalone applications it is common to create an instance of ClassPathXmlApplicationContext or FileSystemXmlApplicationContext www.rajkrrsingh.blogspot.com
  • 13. Ways To Initialize Spring Container www.rajkrrsingh.blogspot.com
  • 14. Type of Dependency Injection Setter method Injection Constructor Injection Configuration File Injection www.rajkrrsingh.blogspot.com
  • 15. Examples for dependency Injection Setup Enviornment for Spring Install JAVA If you are running Windows and installed the JDK in C:jdk1.6.0_15, you would have to put the following line in your C:autoexec.bat file. set PATH=C:jdk1.6.0_15bin;%PATH% set JAVA_HOME=C:jdk1.6.0_15 Unix (Solaris, Linux, etc.), if the SDK is installed in /usr/local/jdk1.6.0_15 and you use the C shell, you would put the following into your .cshrc file. setenv PATH /usr/local/jdk1.6.0_15/bin:$PATH setenv JAVA_HOME /usr/local/jdk1.6.0_15 Download Spring Jars Install Common Logging Download Apache Commons Logging API from http://commons.apache.org/logging Install Eclipse and setup for Spring www.rajkrrsingh.blogspot.com
  • 16. Reference to Other Beans (DI) www.rajkrrsingh.blogspot.com
  • 17. Some More Example Alias Import Initialize bean static Bean Factory Method <bean id="mp3ply" class="com.test.Mp3Player" factory-method="factoryMethod"> </bean> public Class Mp3Player{ private static Mp3Player mp3ply = new Mp3Player(); public Mp3Player(){} public static Mp3Player factoryMethod(){ return mp3ply; } } www.rajkrrsingh.blogspot.com
  • 18. Some More Example Collections Inner Beans Autowire Namespaces Depends Upon ApplicationContextAware interface BeanNameAware interface InitializingBean interface www.rajkrrsingh.blogspot.com
  • 19. Beans Scopes Scope Description This scopes the bean definition to a single instance per singleton Spring IoC container (default). This scopes a single bean definition to have any number of prototype object instances. This scopes a bean definition to an HTTP request. Only request valid in the context of a web-aware Spring ApplicationContext. This scopes a bean definition to an HTTP session. Only session valid in the context of a web-aware Spring ApplicationContext. This scopes a bean definition to a global HTTP session. global-session Only valid in the context of a web-aware Spring ApplicationContext. www.rajkrrsingh.blogspot.com
  • 20. Beans Life Cycle  When a bean is instantiated, it may be required to perform some initializatio to get it into a usable state When the bean is no longer required and is removed from the container, some cleanup may be required. Register the shutdown hook for the ApplicationContext Callback Methods: Init and destroy methods The init-method attribute specifies a method that is to be called on the bean immediately upon instantiation destroy-method specifies a method that is called just before a bean is removed from the container. www.rajkrrsingh.blogspot.com
  • 21. Beans Post Processors  The BeanPostProcessor interface defines callback methods that you can implement to provide your own instantiation logic You can also implement some custom logic after the Spring container finishe instantiating, configuring, and initializing a bean by impl PostProcessors You can have multiple Bean Post processor and can define their order of execution ApplicationContext automatically detects any bean as a post processor who implements BeanPostProcessor Interface www.rajkrrsingh.blogspot.com
  • 22. Aspect Oriented Programming(AOP) ObjectA ObjectC methodA() methodA() . . . . methodN() methodN()v Logging Security Aspect Configuration ObjectB ObjectD methodA() methodA() . . . . methodN() methodN() www.rajkrrsingh.blogspot.com
  • 23. Aspect Oriented Programming(AOP) Complements OO programming Aspect Oriented Programming entails breaking down program logic into dist parts called so-called concerns Cross-cutting concerns are conceptually separate from the application's business logic, e.g. ogging, auditing, declarative transactions, security, and caching etc Spring AOP module provides interceptors to intercept an application, for example, when a method is executed, you can add extra functionality before or after the method execution. www.rajkrrsingh.blogspot.com
  • 24. Aspect Oriented Programming(AOP) Components of AOP Aspect – unit of modularity for crosscutting concerns Join point – well-defined points in the program flow Pointcut – join point queries where advice executes Advice – the block of code that runs based on the pointcut definition Weaving – can be done at runtime or compile time. Inserts the advice (crosscutting concerns) into the code (core concerns). www.rajkrrsingh.blogspot.com
  • 25. Setting up AOP Environment in Eclipse AOP Dependencies AspectJ: http://www.eclipse.org/aspectj/downloads.php AOP Alliance: http://aopalliance.sourceforge.net/ CGILIB: http://cglib.sourceforge.net/ Spring 3 ASM: http://asm.ow2.org/ Examples….. www.rajkrrsingh.blogspot.com
  • 26. Spring DAO and ORM  Built in code templates that support JDBC, Hibernate, JDO, and iBatis SQL Maps Simplifies data access coding by reducing redundant code and helps avoid common errors.  Alleviates opening and closing connections in your DAO code. No more ThreadLocal or passing Connection/Session objects. Transaction management is handled by a wired bean You are dropped into the template with the resources you need for data access – Session, PreparedStatement, etc. Optional separate JDBC framework www.rajkrrsingh.blogspot.com
  • 27. JdbcTemplate Central class in the JDBC core package Handles the creation and release of resources. Executes the core JDBC workflow like statement creation and Execution  Executes – SQL queries – update statements – stored procedure calls – iteration over ResultSets – extraction of returned parameter values. Also catches JDBC exceptions www.rajkrrsingh.blogspot.com
  • 28. DataSource Configuration www.rajkrrsingh.blogspot.com
  • 29. Spring ORM : Working with Hibernate www.rajkrrsingh.blogspot.com
  • 30. Spring ORM : Working with Hibernate www.rajkrrsingh.blogspot.com
  • 31. Q&A www.rajkrrsingh.blogspot.com
  • 32. Thanks if you have any query concerns write to me on rajkrrsingh@gmail.com www.rajkrrsingh.blogspot.com