Spring AOP

10,431 views

Published on

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

Published in: Technology
0 Comments
13 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
10,431
On SlideShare
0
From Embeds
0
Number of Embeds
214
Actions
Shares
0
Downloads
621
Comments
0
Likes
13
Embeds 0
No embeds

No notes for slide































  • Crosscutting. Does the concern have a crosscutting nature?
    Aspectizability. Can the concern be resolved by AOP?
    Obliviousness. Is neither the existence nor the execution of the Aspect code apparent by examining the base code (Which allows greater Separation of Concerns)?
    Code reduction. Does it reduce code?
    Reliability. Does it reduce the chance of making mistakes?
    Modularity. Does it reduce tangling (multiple concerns intermixed) and scattering (spread of code for a concern)?
    Evolvability. Does it make it easier to modify the implementation when requirements change?
    Cost-effectiveness. Do the benefits (Code Reduction, Reliability, Modularity, Evolvability) outweigh the costs (possible increase of complexity and/or decrease of performance)?

  • Spring AOP

    1. 1. Spring AOP Aspect-Oriented Programming with Spring
    2. 2. Jeroen Rosenberg, Java Developer jeroen.rosenberg@gmail.com
    3. 3. Table of Contents
    4. 4. Table of Contents ‣ Why Aspect-Oriented Programming?
    5. 5. Table of Contents ‣ Why Aspect-Oriented Programming? ‣ Basic AOP Concepts
    6. 6. Table of Contents ‣ Why Aspect-Oriented Programming? ‣ Basic AOP Concepts ‣ Getting Started with Spring AOP
    7. 7. Table of Contents ‣ Why Aspect-Oriented Programming? ‣ Basic AOP Concepts ‣ Getting Started with Spring AOP ‣ Benefits and Drawbacks
    8. 8. Table of Contents ‣ Why Aspect-Oriented Programming? ‣ Basic AOP Concepts ‣ Getting Started with Spring AOP ‣ Benefits and Drawbacks ‣ When to Use Spring AOP?
    9. 9. Aspect-Oriented Programming (AOP) enables modularization of cross- cutting concerns
    10. 10. Cross-cutting Concerns
    11. 11. Cross-cutting Concerns ‣ Logging ‣ Validation ‣ Transaction Management ‣ Security ‣ Caching
    12. 12. Code Tangling
    13. 13. Code Tangling Coupling of different concerns
    14. 14. Code Scattering
    15. 15. Code Scattering Same concern spread across modules
    16. 16. The encouraged approach for implementing cross-cutting concerns
    17. 17. The encouraged approach for implementing cross-cutting concerns
    18. 18. 1. Solve core problem The encouraged approach for implementing cross-cutting concerns
    19. 19. 1. Solve core problem The encouraged approach for implementing cross-cutting concerns
    20. 20. 1. Solve core problem 2. Write aspects The encouraged approach for implementing cross-cutting concerns
    21. 21. 1. Solve core problem 2. Write aspects The encouraged approach for implementing cross-cutting concerns
    22. 22. 1. Solve core problem 3. Weave at runtime 2. Write aspects The encouraged approach for implementing cross-cutting concerns
    23. 23. AOP Terminology
    24. 24. AOP Terminology ‣ An aspect is a module that encapsulates advice and pointcuts
    25. 25. 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
    26. 26. 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
    27. 27. 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
    28. 28. Spring AOP Java-based AOP framework
    29. 29. Spring uses dynamic proxying for aspect weaving
    30. 30. Calls on the object reference will be calls on the proxy and the proxy delegates to all of the relevant advices
    31. 31. Regular method invocation Calls on the object reference will be calls on the proxy and the proxy delegates to all of the relevant advices
    32. 32. Regular method invocation Proxied method invocation Calls on the object reference will be calls on the proxy and the proxy delegates to all of the relevant advices
    33. 33. Spring offers 3 ways to accomplish AOP support Annotation based Schema based Schema based with AspectJ with AspectJ without AspectJ Very easy to Bloated Easy to configure configure configuration Horizontal class Horizontal class Horizontal class relationships at relationships at relationships at code level deployment level deployment level Degrades Enables portability Enables portability portability
    34. 34. Configuration Schema based aspect configuration without AspectJ
    35. 35. Sample XML configuration
    36. 36. Demo
    37. 37. Benefits No special compiler required to allow per-object interception
    38. 38. Drawbacks Lower performance
    39. 39. AOP Suitability Cost-effectiveness Code reduction Aspectizability Obliviousness Crosscutting Concern Evolvability Modularity Reliability Logging V V V V V Validation V V V V V V V ? Transaction Management V V V V V V V V Security V V V ? V ? ? Caching V V V ? ? V ? V
    40. 40. Modularization of Schema based cross cutting concerns aspect configuration Auto-proxying for aspect weaving Summary

    ×