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.

Springaopdecoded ajip


Published on

  • Be the first to comment

  • Be the first to like this

Springaopdecoded ajip

  1. 1. Spring AOP DecodedMak Bhatamrekar Java Concept Pros
  2. 2. Agenda• The Problem• Measuring Performance Project• AOP At Glance• PointCut And Advice• Logging Project• AOP Configuration• AOP Proxy & Weaver• Recap
  3. 3. 
  4. 4. 
  5. 5. Why AOP
  6. 6. Measuring Performancepublic void convertToFixedDeposit() throws Exception {//Your Business LogicThread.sleep(DEFAULT_SLEEP_INTERVAL);log.debug("convertToFixedDeposit Complete");}
  7. 7. Measuring Performancepublic void convertToFixedDeposit() throws Exception {StopWatch monitor = new StopWatch();monitor.start("convertToFixedDeposit");//Your Business LogicThread.sleep(DEFAULT_SLEEP_INTERVAL);log.debug("convertToFixedDeposit Complete");monitor.stop();log.debug(monitor.prettyPrint());}
  8. 8. ChallengesWhat If it has to be done across 10 classes and 10 methods•Not DRY Code•Testing Involved•Complexity Increases with Number Of Methods•Code change is permanent•Invasive•Time Consuming
  9. 9. IS There a Easy Solution
  10. 10. AOP Performance ProjectBeans.xmlMyMain.javaMyServiceSpringImpl
  11. 11. Spring AOP At Glance
  12. 12. Spring AOP At Glance• Pointcut(Expression)• Advice• Aspect = PointCut + Advice• AOP Proxy• Weaver - Spring AOP orAspectJ
  13. 13. Defining Pointcuts• execution(<expression>) –Methods Pointcuts• within() - Class Pointcuts• Bean() - Bean Pointcuts
  14. 14. Execute Expressionexecution(“< expression>“); //For Method PointCutspublic String com.mypr.Demo.getName());public * get*();* get*()* get*(*)* get*(..)* com.mypr.*.*get*()
  15. 15. Within & Bean Expressionwithin(“< filter>“); //Applies to all the methods of the classes matching filterwithin(*)within(*)within( || within(DemoInterface2+)bean(*Service)
  16. 16. Advice Types• Before Advice• After Returning Advice• After Throwing Advice• Around Advice
  17. 17. Declaring AOP• AspectJ Annotation Based– More Flexible, Such as Combined named Pointcuts– Encapsulation• Spring XML Based– Any JDK Version is Good– Good Choice to configure enterprise services
  18. 18. @AspectJ Annotation Style• @Aspect• @Pointcut(“execution(* com…abc.Hello(..)”)• @Before• @After• @AfterReturning(pointcut=“”,returning=“retVal”)• @AfterThrowing• @Around
  19. 19. XML Based Configuration
  20. 20. AOP Proxy
  21. 21. WeaverSpring AOP• No Special Compilation• Supports Only MethodPointcuts• Advise execution on SpringBeansAspectJ• Needs AspectJ Compiler• Support All Pointcuts• Advice all domain objects
  22. 22. Reference Links•••
  23. 23. Spring AOP DecodedMak Bhatamrekargithub : : mak-bkarurl : www.careerinjava.com Java Concept Pros