Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Spring AOP

11,115 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
  • Be the first to comment

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

×