Java Training-Spring Framework
Java Training-Spring Framework
Java Training-Spring Framework
What is Spring?
-
Spring
MVC
Spring
Batch
Spring
WebFlow
Spring
Spring
Boots
Framework
Spring
Data
Spring
Security
Spring
Integration
And
...
Overview
History
Goal
Spring Modules
Spring Triangle
Awards
Java 1.5+
Java 1.4+
Java 1.3+
Goals
Is modular
Spring Modules
Core container
Context
provide the fundamental parts of the framework, including IoC and Dependency
Injection features
Expression language
AOP
Aspect
Instrumentation
Data Access/Integration
JDBC
ORM
provides integration layers for popular object-relational mapping APIs, including JPA,
JDO, Hibernate and iBatis
OXM
Data Access/Integration
JMS
Transaction
WEB
The Web layer consists of the spring-web, spring-webmvc, spring-websocket, and springwebmvc-portlet modules.
WEB-Servlet (spring-webmvc )
WEB-Portlet (spring-webmvc-portlet)
Test
The spring-test
supports the unit testing and integration testing of Spring components with JUnit
or TestNG. It provides consistent loading of Spring ApplicationContexts and
caching of those contexts. It also provides mock objects that you can use to test
your code in isolation.
De
pe
nd
en
cy
P
AO
Inj
ec
tio
n
POJO
IoC Container
Packages
org.springframework.beans
org.springframework.context
BeanFactory
ApplicationContext
a sub-interface of BeanFactory, represents the Spring IoC container, adds more enterprisespecific functionality
IoC Container
IoC Container
Configuration metadata
IoC Container
Instantiating a container
BeanFactory
What is Bean?
The objects that form the backbone of your application and that are
managed by the Spring IoC Container are called beans
configuration metadata
Bean's dependencies
Description
class
name
scope
constructor-arg
properties
autowiring mode
lazy-initialization mode
initialization method
destruction method
Dependency Injection
No
Inner Beans
Collections
Straight values
Idref
Or
Inner Beans
Aliases
Injecting Collections
Element
Description
<list>
<set>
<map>
<props>
Injecting Collections
Bean Scopes
Scope
Description
singleton
prototype
scope
This attribute specifies the scope of the objects created from a particular bean
definition
request
session
global-session
Initialization
InitializingBean
Destruction
DisposableBean
ApplicationContextAware
BeanPostProcessor
defines callback methods that you can implement to provide your own
instantiation logic, dependency-resolution logic etc
BeanFactoryPostProcessor
http://www.dineshonjava.com/2012/07/writing-beanfactorypostprocessor-in.html#.VQWYyI7syM8
Autowiring Modes:
Mode
Description
no
byName
byType
constructor
autodetect
Description
Overriding possibility
Confusing nature
@Autowired on Properties
@Autowired on Constructors
@Qualifier
@Resource Annotation
@Component
@Repository
@Service
Generic stereotype
@Controller
MessageSource
For i18n
Event Handling
Event Handling
No
ContextRefreshedEvent.
This event is published when the ApplicationContext is either initialized or
refreshed
ContextStartedEvent.
This event is published when the ApplicationContext is started using the start()
method on the ConfigurableApplicationContext interface
ContextStoppedEvent
This event is published when the ApplicationContext is stopped using the
stop() method on the ConfigurableApplicationContext interface
ContextClosedEvent
This event is published when the ApplicationContext is closed using the close()
method on the ConfigurableApplicationContext interface..A closed context
reaches its end of life; it cannot be refreshed or restarted.
RequestHandledEvent
This is a web-specific event telling all beans that an HTTP request has been
serviced.