KCJUG - Jason Bedell

namibiancurrishInternet and Web Development

Nov 12, 2013 (3 years and 7 months ago)

61 views

Spring Framework

Kansas City Java User’s Group

Jason W. Bedell

July 12, 2006

Overview


J2EE Alternative


Inversion of Control (IoC) vs. Dependency
Injection (DI)


Aspect Oriented Programming (AOP)


Spring Modules


Example Application


Dependency Injection Example


AOP Example


Real
-
World Application


DI & AOP

J2EE Alternative


Heavyweight complexity


An easier way to connect disparate
components


Enterprise Services using POJO’s


Other players: PicoContainer, HiveMind,
Avalon

IoC and Dependency
Injection


IoC an earlier, more general term


Think “plug
-
ins”


Behavior is configured instead of
programmed.


Dependency Injection is a pattern to achieve
IoC


Alternative patterns: Service Locator

Aspect Oriented
Programming


“AOP enables
modularization of
crosscutting concerns”


AOP Terms:


Aspects


Joinpoints


Advice


Cutpoints


Introductions


Targets


Proxy


Weaving


Alternative AOP Containers:
AspectJ, JBoss


Course Service
Student Service
Misc Service
Security
Transactions
Auditing
/
Logging
AOP Terms


Aspects:


The modularized logic that is being applied throughout an application.


Examples: Logging, Security, Transaction Management, etc.


Joinpoints


An execution point where an aspect
can

be applied.


Examples: a method being called, a method returning, an exception being thrown, a field
being modified, etc.


Advice


The actual implementation of an aspect.


Cutpoints


The joinpoints where advice
should

be applied.


Introductions


A method or attribute that you introduce to an existing class


Targets


A class that is being advised


Example: Course Service, Student Service, etc.


Proxy


The object created after applying advice to a target object.


Weaving


The process of applying aspects to target objects to create a new, proxied object.


Weaving can occur at compile time, classload time, runtime.

Course Service
Student Service
Misc Service
Security
Transactions
Auditing
/
Logging
Spring Modules


The core container


Application context module


AOP Module


JDBC abstraction and DAO
module


O/R mapping integration
module
(supports Hibernate, JDO,
Oracle TopLink, Apache OJB, and iBATIS)


Web module


MVC framework

Core Container and Supporting Utilities
JDBC and DAO
Module
Application
Context Module
MVC
Framework
O
/
R Mapping
Module
Web Context
and Utility
Module
AOP Module
Example Application

Dependency Injection (DI) Example

+
askQuestion
() :
string
(
idl
)
-
eightBallService
:
EightBallService
EightBallApp
+
askQuestion
() :
string
(
idl
)
+
findAnswer
() :
string
(
idl
)
-
answerDAO
:
AnswerDAO
EightBallService
-
End
1
1
-
End
2
*
AnswerDAO
+
findAnswer
() :
string
(
idl
)
DummyAnswerDAO
+
findAnswer
() :
string
(
idl
)
FileAnswerDAO
AnswerDAO
«bind»
«bind»
+
findAnswer
() :
string
(
idl
)
HibernateAnswerDAO
AnswerDAO
«bind»
EightBallApp
User
askQuestion
:=
askQuestion
()
Service
askQuestion
:=
askQuestion
()
AnswerDAO
findAnswer
:=
findAnswer
()
answer
answer
answer
Actor
1
askQuestion
«uses»
Example Application

AOP Example


Determine what Joinpoint to use as our Cutpoint


Implement the Aspect in the form of Advise


Define a Spring Advisor


Spring Advisor: the combination of advice that defines the
aspect’s behavior and a pointcut defining where the aspect
should be executed.


Spring allows you to define your own advisor or use a
predefined, packaged advisor


Define your bean proxy


Inject your Advisor into the Proxy as an Interceptor



Real World Example

DI & AOP


Application Tier


SpringMVC Framework


Tiles, JSTL


Service Tier


Service POJO Targets


Persistence Tier


DAO POJO Targets


Hibernate Framework


Security Aspect


Acegi Framework Advisor


Transaction Support Aspect


Spring Transaction
Management Advisor


RDBMS
Service Tier
Domain Model
Model
/
Data
Transfer
Objects
(
DTO
)
Views
Controllers
Persistence Tier
HibernateDTO
File System
FileSystemDTO
Application Tier
Transaction Support
Security