Spring AOP

jeroen_rosenberg 5,629 views 40 slides Apr 29, 2010
Slide 1
Slide 1 of 40
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40

About This Presentation

This keynote provides a short introduction for using Spring AOP to modularize your cross cutting concerns and keep your code clean.


Slide Content

Spring AOP
Aspect-Oriented Programming with Spring

Jeroen Rosenberg, Java Developer
[email protected]

Table of Contents

Table of Contents
‣Why Aspect-Oriented Programming?

Table of Contents
‣Why Aspect-Oriented Programming?
‣Basic AOP Concepts

Table of Contents
‣Why Aspect-Oriented Programming?
‣Basic AOP Concepts
‣Getting Started with Spring AOP

Table of Contents
‣Why Aspect-Oriented Programming?
‣Basic AOP Concepts
‣Getting Started with Spring AOP
‣Benefits and Drawbacks

Table of Contents
‣Why Aspect-Oriented Programming?
‣Basic AOP Concepts
‣Getting Started with Spring AOP
‣Benefits and Drawbacks
‣When to Use Spring AOP?

Aspect-Oriented Programming (AOP)
enables modularization of cross-
cutting concerns

Cross-cutting Concerns

Cross-cutting Concerns
‣Logging
‣Validation
‣Transaction
Management
‣Security
‣Caching

Code Tangling

Coupling of different concerns
Code Tangling

Code Scattering

Code Scattering
Same concern spread across
modules

The encouraged approach for implementing cross-cutting concerns

The encouraged approach for implementing cross-cutting concerns

The encouraged approach for implementing cross-cutting concerns
1. Solve core problem

The encouraged approach for implementing cross-cutting concerns
1. Solve core problem

The encouraged approach for implementing cross-cutting concerns
1. Solve core problem
2. Write aspects

The encouraged approach for implementing cross-cutting concerns
1. Solve core problem
2. Write aspects

The encouraged approach for implementing cross-cutting concerns
1. Solve core problem
2. Write aspects
3. Weave at runtime

AOP Terminology

‣An aspect is a module that encapsulates advice and pointcuts
AOP Terminology

‣An aspect is a module that encapsulates advice and pointcuts
‣An advice is code to be executed at a join point selected by a pointcut
AOP Terminology

‣An aspect is a module that encapsulates advice and pointcuts
‣An advice is code to be executed at a join point selected by a pointcut
‣A pointcut is an expression that selects one or more join points
AOP Terminology

‣An aspect is a module that encapsulates advice and pointcuts
‣An advice is code to be executed at a join point selected by a pointcut
‣A pointcut is an expression that selects one or more join points
‣A join point is a point in the execution of a program
AOP Terminology

Spring AOP
Java-based AOP framework

Spring uses dynamic proxying for aspect weaving

Calls on the object reference will be calls on the proxy and the proxy
delegates to all of the relevant advices

Calls on the object reference will be calls on the proxy and the proxy
delegates to all of the relevant advices
Regular method invocation

Calls on the object reference will be calls on the proxy and the proxy
delegates to all of the relevant advices
Regular method invocation Proxied method invocation

Spring offers 3 ways to accomplish AOP support
Annotation based
with AspectJ
Schema based
with AspectJ
Schema based
without AspectJ
Very easy to
configure
Bloated
configuration
Easy to configure
Horizontal class
relationships at
code level
Horizontal class
relationships at
deployment level
Horizontal class
relationships at
deployment level
Degrades
portability
Enables portabilityEnables portability

Schema based aspect
configuration without AspectJ
Configuration

Sample XML configuration

Demo

No special compiler required to allow
per-object interception
Benefits

Drawbacks
Lower performance

AOP Suitability
Concern
Logging VVVV V
Validation VVVVVVV?
Transaction ManagementVVVVVVVV
Security VVV? V??
Caching VVV??V?V
CrosscuttingAspectizabilityObliviousnessCode reductionReliabilityModularityEvolvabilityCost-effectiveness

Summary
Modularization of
cross cutting concerns
Auto-proxying for
aspect weaving
Schema based
aspect configuration