S
P
R
IN
GF
R
A
M
E
W
O
R
KT
U
T
O
R
IA
L
A
G
E
N
D
A
1.Overview
2.Spring 10 Platform
3.Spring Framework
4.Environment Setup
5.Inversion of Control
6.Dependency injection
7.SpringWeb MVC
Framework 8.Spring Security
O
V
E
R
V
I
E
W
Springis the most popular application development frameworkfor enterprise
Java.Millions of developers aroundthe world use Spring Framework to
create high performing,easily testable,reusable code.
October 2002 The first version was released
June 2003 The framework was first released under the Apache 2.0 license March
2004 The first milestone release - 1.0
October 2006 Spring2.0
November 2007 Spring2.5
December 2009 Spring3.0
December 2011 Spring3.1
B
E
N
E
F
I
T
S
• Spring enables developersto develop enterprise-class applications using
POJOs.
• Spring is organized in a modular fashion.
• Spring does not reinvent thewheelinstead,it truly makes useof some of
the existing technologies.
• Testingan applicationwritten with Springis simple because environment
dependent code is moved into this framework.
• Spring's webframework is a well-designed web MVC framework.
• Lightweight loC containerstend to be lightweight,especially when
compared to EJB containers.
• Spring provides a consistent transaction management.
S
P
R
I
N
G1
0P
L
A
T
F
O
R
M
-
-
-
- - 0 0 . A
RelM! O . ,I N o " RPl.it•on;il
S
P
R
I
N
G1
0P
L
A
T
F
O
R
M·C
O
R
E
Spring
Framework
Provides core support for dependency
injection,transaction management,web apps,
data access,messaging and more.
Spring
Security
Protects your application with
comprehensive and extensible
authentication and authorization support.
Groovy Brings high-productivity dynamic
language features to the JVM.
Reactor A foundation for reactive fast data
applications on the JVM.
S
P
R
IN
G1
0P
L
A
T
F
O
R
M·D
A
T
A
Spring 10 addresses modern data landscape -whether it
be document,graph,key-value,relational,or simply
unstructured files.
S
P
R
I
N
G1
0P
L
A
T
F
O
R
M·W
O
R
K
L
O
A
D
S
Integration Channels,Adapters,Filters,Transformers
Batch Jobs,Steps, Readers,Writers
Bigdata Ingestion,Export,Orchestration,Hadoop
Web Controllers, REST
,WebSocket
S
P
R
I
N
GF
R
A
M
E
W
O
R
K
Spring is the most popular application development framework
for enterprise Java.
The core features of the Spring Framework can be used in
developing any Java application, but there are extensions for
buildingweb applications on top of the Java EE platform.
Springenables you to build applications from "plainold Java
objects" (POJOs) and to apply enterprise services non-
invasively to POJOs. This capability applies to the Java SE
programming model and to full and partial Java EE.
S
P
R
I
N
GF
R
A
M
E
W
O
R
K·C
O
M
P
O
N
E
N
T
S
Spring FratnllWOllcRuntime
DataAccess/Integration Web
( JDBC ) B R B
(---=:-!
L : : _ j 0
(. .
)
Tranaec:tlone L . : : : _ j
L..:::_j
( AOP ) ( Aepecte ) ( lnetrumentatk>n )
Core Container
( Beans ) ( Core ) ( C o n xt
)
=
=
"
(
)
S
P
R
IN
GF
R
A
M
E
W
O
R
K·C
O
R
EC
O
N
T
A
I
N
E
R
• The Core module provides the fundamental parts of the framework,
includingthe loC and Dependency Injectionfeatures.
• The Bean module provides BeanFactory which is a sophisticated
implementation of thefactory pattern.
• The Context module builds on the solid base provided by the Core
and Beans modules and it is a mediumto access any objects
defined and configured.
• The Expression Language module provides a powerful expression
language for querying and manipulatingan object graph at runtime.
S
P
R
I
N
GF
R
A
M
E
W
O
R
K·D
A
T
AA
C
C
E
S
S
• The JDBC module provides a JDBC-abstraction layerthat removes
the need to do tedious JDBC related coding.
• The ORM module provides integration layers for popular object
relational mappingAPls,including JPA,JDO,Hibernate,and iBatis.
• The OXM module provides an abstraction layer that supports
Object/XML mapping implementations for JAXB, Castor,XMLBeans,
JiBX and XStream.
• The Java MessagingService JMS module contains features for
producingand consuming messages.
• The Transaction modulesupports programmatic and declarative
transactionmanagement for classes that implement special
interfaces andforall your POJOs.
S
P
R
I
N
GF
R
A
M
E
W
O
R
K·W
E
B
• Spring's Web module provides basic web-oriented integration features such as
multipart file-upload functionality andthe initialization of the loC containerusingservlet
listeners and aweb-oriented application context.
• The Web-Servlet module contains Spring's model-view-cont roller (MVC)
implementation forweb applications. Spring's MVC framework provides a clean
separation between domainmodelcode andweb forms,and integrates withall the other
features of the SpringFramework.
• The Web-Portlet module provides the MVC implementation to be used in a portlet
environment and mirrors the functionality of Web-Serv iet module.
• The Web-Struts module contains the support classes for integratinga classic Struts
web tierwithina Springapplication.
E
N
V
IR
O
N
M
E
N
TS
E
T
U
P
E
C
L
I
P
S
E
• Download Eclipse from http://www.eclipse.org/downloads
• Decompress downloaded file into the directory of your
choice (e.g."C:Eclipse" on Windows)
• ???
• PROFIT!!!
M
A
V
E
NIN
T
E
G
R
A
T
I
O
NF
O
RE
C
L
I
P
S
E
• Open Eclipse
• Go to Help -> Eclipse Marketplace
• Search by Maven
• Click "Install" button at "Maven Integration for Eclipse"
section
• Follow the instruction step by step
H
E
L
L
OW
O
R
L
D
httRs://github.com/soaserele/sRring-tutorial/tree/master/hello
IN
V
E
R
SIO
NO
FC
O
N
T
RO
L
Inversion of control (loC) is a programming technique inwhich
object coupling is bound at runtime by an assembler object
and is typically not known at compiletime using static
analysis.In order for the assembler to bind objects to one
another,the objects must possess compatible abstractions.
•is a concept in application development
•"don't call me,I'll call you"
•one form is Dependency Injection (DI)
IN
V
E
R
SIO
NO
FC
O
N
T
RO
L
Objects (POJOs)
produces
Fully
configured system
Ready for
Use
Your
Business
The Spring
Container
Configuration
Metadata
IN
V
E
R
SIO
NO
FC
O
N
T
RO
L
The Springcontainer is at the core of the Spring Framework.
The Springcontainer uses dependency injection (DI) to
manage the components that make upan application.
The container will create the objects, wire them together,
configurethem, and manage their complete lifecycle from
creation till destruction.
The container gets its instructions onwhat objects to
instantiate,configure,and assemble by readingconfiguration
metadata provided.The configuration metadata can be
represented either by XML, Java annotations, or Java code.
D
E
P
E
N
D
E
N
C
YIN
J
E
C
T
I
O
NC
O
N
T
A
I
N
E
R
S
• Spring BeanFactory Container
This is the simplest container providing basic support for DI.There are
a number of implementations of the BeanFactory interface that
come supplied straight out-of-the-box with Spring.The most
commonly used BeanFactory implementation is the XmlBeanFactory
class.
• SpringApplicationContext Container
The ApplicationContext includes all functionality of the BeanFactory,it
is generally recommended overthe BeanFactory.It adds more
enterprise specific functionality such as the ability to resolve textual
messages from a properties file andthe ability to publish application
events to interested event listeners.
C
O
N
T
A
I
N
E
RSE
X
A
M
P
L
E
htt12s://github.com/soaserele/s12ring-tutorial/tree/master /beanfactocv.
B
E
A
N
S
B
E
A
N
S
The objects that form the backbone of your application and
that are managed by the Spring loC container are called
beans.
A bean is an object that is instantiated,assembled,and
otherwise managed by a Spring loC container.These beans
are created with the configuration metadata that you supply to
the container,for example,in the form of XML <bean/>
definitions which you have already seen in previous chapters.
B
E
A
N
S·D
E
F
I
N
I
T
I
O
N
The bean definition containsthe information called
configuration metadata which is needed for the container
to know the followings:
•How to create a bean
•Bean's lifecycle details
•Bean's dependencies
B
E
A
N
S·D
E
F
I
N
I
T
I
O
N
< >
Property Description
class* The bean class to be used to create the
bean.
name The unique bean identifier.
scope The scope of the objects created from a
particular bean definition.
autowiring Used to specify autowire mode for a bean
mode definition
lazy- Tells the loC container to create a bean
IllMade with Sldes.com initialization instance when it is first requested,rather
Property
B
E
A
N
S·D
E
F
I
N
I
T
I
O
N
Description
constructor
arg
Used to inject the dependencies into
the class througha class constructor
properties Used to inject the dependencies into
the class throughsetter methods
,,. ..
Property
B
E
A
N
S·D
E
F
I
N
I
T
I
O
N
Description
initialization
method
A callback to becalledjust after all
necessary properties on the bean have
been set by the container.
destruction
method
A callback to be used when the
container containing the bean is
destroyed.
,,. ..
B
E
A
ND
E
F
I
N
I
T
I
O
NE
X
A
M
P
L
E
htt12s://github.
com/soaserele/s12ring-tutorial/tree/master/beandef
,,. ..
B
E
A
N
S·S
C
O
P
E
S
Scope Description
singleton Thisscopesthe beandefinitionto asingle
instanceper SpringloCcontainer (default).
prototype This scopes a single bean definition to have
any number of object instances.
request * Thisscopesabeandefinitionto an HTTP
request.
session * Thisscopesabeandefinitionto an HTTP
.
session.
I I Made with Sl des.com global- Thisscopesabeandefinitionto aglobal HTTP
< >

Screenshot from 2024-05-28 16-46-45 (30 files merged).ppt

  • 1.
  • 2.
    A G E N D A 1.Overview 2.Spring 10 Platform 3.SpringFramework 4.Environment Setup 5.Inversion of Control 6.Dependency injection 7.SpringWeb MVC Framework 8.Spring Security
  • 3.
    O V E R V I E W Springis the mostpopular application development frameworkfor enterprise Java.Millions of developers aroundthe world use Spring Framework to create high performing,easily testable,reusable code. October 2002 The first version was released June 2003 The framework was first released under the Apache 2.0 license March 2004 The first milestone release - 1.0 October 2006 Spring2.0 November 2007 Spring2.5 December 2009 Spring3.0 December 2011 Spring3.1
  • 4.
    B E N E F I T S • Spring enablesdevelopersto develop enterprise-class applications using POJOs. • Spring is organized in a modular fashion. • Spring does not reinvent thewheelinstead,it truly makes useof some of the existing technologies. • Testingan applicationwritten with Springis simple because environment dependent code is moved into this framework. • Spring's webframework is a well-designed web MVC framework. • Lightweight loC containerstend to be lightweight,especially when compared to EJB containers. • Spring provides a consistent transaction management.
  • 5.
    S P R I N G1 0P L A T F O R M - - - - - 00 . A RelM! O . ,I N o " RPl.it•on;il
  • 6.
    S P R I N G1 0P L A T F O R M·C O R E Spring Framework Provides core supportfor dependency injection,transaction management,web apps, data access,messaging and more. Spring Security Protects your application with comprehensive and extensible authentication and authorization support. Groovy Brings high-productivity dynamic language features to the JVM. Reactor A foundation for reactive fast data applications on the JVM.
  • 7.
    S P R IN G1 0P L A T F O R M·D A T A Spring 10 addressesmodern data landscape -whether it be document,graph,key-value,relational,or simply unstructured files.
  • 8.
    S P R I N G1 0P L A T F O R M·W O R K L O A D S Integration Channels,Adapters,Filters,Transformers Batch Jobs,Steps,Readers,Writers Bigdata Ingestion,Export,Orchestration,Hadoop Web Controllers, REST ,WebSocket
  • 9.
    S P R I N GF R A M E W O R K Spring is themost popular application development framework for enterprise Java. The core features of the Spring Framework can be used in developing any Java application, but there are extensions for buildingweb applications on top of the Java EE platform. Springenables you to build applications from "plainold Java objects" (POJOs) and to apply enterprise services non- invasively to POJOs. This capability applies to the Java SE programming model and to full and partial Java EE.
  • 10.
    S P R I N GF R A M E W O R K·C O M P O N E N T S Spring FratnllWOllcRuntime DataAccess/Integration Web (JDBC ) B R B (---=:-! L : : _ j 0 (. . ) Tranaec:tlone L . : : : _ j L..:::_j ( AOP ) ( Aepecte ) ( lnetrumentatk>n ) Core Container ( Beans ) ( Core ) ( C o n xt ) = = " ( )
  • 11.
    S P R IN GF R A M E W O R K·C O R EC O N T A I N E R • The Coremodule provides the fundamental parts of the framework, includingthe loC and Dependency Injectionfeatures. • The Bean module provides BeanFactory which is a sophisticated implementation of thefactory pattern. • The Context module builds on the solid base provided by the Core and Beans modules and it is a mediumto access any objects defined and configured. • The Expression Language module provides a powerful expression language for querying and manipulatingan object graph at runtime.
  • 12.
    S P R I N GF R A M E W O R K·D A T AA C C E S S • The JDBCmodule provides a JDBC-abstraction layerthat removes the need to do tedious JDBC related coding. • The ORM module provides integration layers for popular object relational mappingAPls,including JPA,JDO,Hibernate,and iBatis. • The OXM module provides an abstraction layer that supports Object/XML mapping implementations for JAXB, Castor,XMLBeans, JiBX and XStream. • The Java MessagingService JMS module contains features for producingand consuming messages. • The Transaction modulesupports programmatic and declarative transactionmanagement for classes that implement special interfaces andforall your POJOs.
  • 13.
    S P R I N GF R A M E W O R K·W E B • Spring's Webmodule provides basic web-oriented integration features such as multipart file-upload functionality andthe initialization of the loC containerusingservlet listeners and aweb-oriented application context. • The Web-Servlet module contains Spring's model-view-cont roller (MVC) implementation forweb applications. Spring's MVC framework provides a clean separation between domainmodelcode andweb forms,and integrates withall the other features of the SpringFramework. • The Web-Portlet module provides the MVC implementation to be used in a portlet environment and mirrors the functionality of Web-Serv iet module. • The Web-Struts module contains the support classes for integratinga classic Struts web tierwithina Springapplication.
  • 14.
  • 15.
    E C L I P S E • Download Eclipsefrom http://www.eclipse.org/downloads • Decompress downloaded file into the directory of your choice (e.g."C:Eclipse" on Windows) • ??? • PROFIT!!!
  • 16.
    M A V E NIN T E G R A T I O NF O RE C L I P S E • Open Eclipse •Go to Help -> Eclipse Marketplace • Search by Maven • Click "Install" button at "Maven Integration for Eclipse" section • Follow the instruction step by step
  • 17.
  • 18.
    IN V E R SIO NO FC O N T RO L Inversion of control(loC) is a programming technique inwhich object coupling is bound at runtime by an assembler object and is typically not known at compiletime using static analysis.In order for the assembler to bind objects to one another,the objects must possess compatible abstractions. •is a concept in application development •"don't call me,I'll call you" •one form is Dependency Injection (DI)
  • 19.
    IN V E R SIO NO FC O N T RO L Objects (POJOs) produces Fully configured system Readyfor Use Your Business The Spring Container Configuration Metadata
  • 20.
    IN V E R SIO NO FC O N T RO L The Springcontainer isat the core of the Spring Framework. The Springcontainer uses dependency injection (DI) to manage the components that make upan application. The container will create the objects, wire them together, configurethem, and manage their complete lifecycle from creation till destruction. The container gets its instructions onwhat objects to instantiate,configure,and assemble by readingconfiguration metadata provided.The configuration metadata can be represented either by XML, Java annotations, or Java code.
  • 21.
    D E P E N D E N C YIN J E C T I O NC O N T A I N E R S • Spring BeanFactoryContainer This is the simplest container providing basic support for DI.There are a number of implementations of the BeanFactory interface that come supplied straight out-of-the-box with Spring.The most commonly used BeanFactory implementation is the XmlBeanFactory class. • SpringApplicationContext Container The ApplicationContext includes all functionality of the BeanFactory,it is generally recommended overthe BeanFactory.It adds more enterprise specific functionality such as the ability to resolve textual messages from a properties file andthe ability to publish application events to interested event listeners.
  • 22.
  • 23.
  • 24.
    B E A N S The objects thatform the backbone of your application and that are managed by the Spring loC container are called beans. A bean is an object that is instantiated,assembled,and otherwise managed by a Spring loC container.These beans are created with the configuration metadata that you supply to the container,for example,in the form of XML <bean/> definitions which you have already seen in previous chapters.
  • 25.
    B E A N S·D E F I N I T I O N The bean definitioncontainsthe information called configuration metadata which is needed for the container to know the followings: •How to create a bean •Bean's lifecycle details •Bean's dependencies
  • 26.
    B E A N S·D E F I N I T I O N < > Property Description class*The bean class to be used to create the bean. name The unique bean identifier. scope The scope of the objects created from a particular bean definition. autowiring Used to specify autowire mode for a bean mode definition lazy- Tells the loC container to create a bean IllMade with Sldes.com initialization instance when it is first requested,rather
  • 27.
    Property B E A N S·D E F I N I T I O N Description constructor arg Used to injectthe dependencies into the class througha class constructor properties Used to inject the dependencies into the class throughsetter methods ,,. ..
  • 28.
    Property B E A N S·D E F I N I T I O N Description initialization method A callback tobecalledjust after all necessary properties on the bean have been set by the container. destruction method A callback to be used when the container containing the bean is destroyed. ,,. ..
  • 29.
  • 30.
    B E A N S·S C O P E S Scope Description singleton Thisscopesthebeandefinitionto asingle instanceper SpringloCcontainer (default). prototype This scopes a single bean definition to have any number of object instances. request * Thisscopesabeandefinitionto an HTTP request. session * Thisscopesabeandefinitionto an HTTP . session. I I Made with Sl des.com global- Thisscopesabeandefinitionto aglobal HTTP < >