SlideShare a Scribd company logo
1 of 18
Spring AOPAspect Oriented Programming By SrinivasReddy.S www.java9s.com
Cross Cutting Concerns class Bank{ 	private int balance;    public void withdraw(int amount){ bankLogger.info(“Withdraw –”+amount); tx.begin(); 	balance = this.balance-amount; accountDao.saveBalance(balance); tx.commit(); 	} } www.java9s.com
Cross Cutting Concerns Application Modules Application Modules Application Modules Application Modules Application Modules www.java9s.com
Cross Cutting Concerns Logging Transaction Application Modules Application Modules Application Modules Spring Framework www.java9s.com
AOP – Definitions. ,[object Object]
Joinpoint
Advice
Pointcut
Introduction
Target Object
AOP Proxy
Weavingwww.java9s.com
AOP – Definitions. Logger Advice Advisor Method Method Method Joinpoints Advisor Transaction Manager  www.java9s.com
AOP - Definitions Advice defines what needs to be applied and when. Jointpoint is where the advice is applied. Pointcut is the combination of different joinpoints where the advice needs to be applied. Aspect is applying the Advice at the pointcuts. www.java9s.com
Advice Types Before Advice After returning Advice Around Advice Throws Advice Method Method Method Method Exception www.java9s.com
AOP - Weaving Compile time Class Load Time Runtime – Springs way Caller Target Proxy www.java9s.com
Pointcut  and Advisor POINTCUT CLASSES: Perl5RegexpMethodPointcut JdkRegexpMethodPointcut Pointcut and Advisor in one class: RegexpMethodPointcutAdvisor www.java9s.com
Example public class CustomerImpl implements Customer{ public void browse(){ System.out.println("Browsing the internet"); } } class CafeOwner{ 	void LogInTime(){ System.out.println(“Log  In time and name of the customer”); } 	void LogOutTime(){ System.out.println(“Log Out Time”); } 	void  issueUsageBill(){ System.out.println(“Calculate and bill the customer”); } } www.java9s.com

More Related Content

Similar to Spring AOP

Aspect-Oriented Programming
Aspect-Oriented ProgrammingAspect-Oriented Programming
Aspect-Oriented Programming
Andrey Bratukhin
 
Introduction to Spring
Introduction to SpringIntroduction to Spring
Introduction to Spring
Sujit Kumar
 

Similar to Spring AOP (20)

Spring - Part 3 - AOP
Spring - Part 3 - AOPSpring - Part 3 - AOP
Spring - Part 3 - AOP
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Session 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOPSession 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOP
 
Spring framework part 2
Spring framework  part 2Spring framework  part 2
Spring framework part 2
 
Aspect-Oriented Programming
Aspect-Oriented ProgrammingAspect-Oriented Programming
Aspect-Oriented Programming
 
Migrating & Operating Microsoft Applications in AWS
Migrating & Operating Microsoft Applications in AWSMigrating & Operating Microsoft Applications in AWS
Migrating & Operating Microsoft Applications in AWS
 
How AQR Capital Uses AWS to Research New Investment Signals
How AQR Capital Uses AWS to Research New Investment Signals How AQR Capital Uses AWS to Research New Investment Signals
How AQR Capital Uses AWS to Research New Investment Signals
 
From User Action to Framework Reaction
From User Action to Framework ReactionFrom User Action to Framework Reaction
From User Action to Framework Reaction
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Introduction to aop
Introduction to aopIntroduction to aop
Introduction to aop
 
Introduction to Spring
Introduction to SpringIntroduction to Spring
Introduction to Spring
 
Introducing spring
Introducing springIntroducing spring
Introducing spring
 
From User Action to Framework Reaction
From User Action to Framework ReactionFrom User Action to Framework Reaction
From User Action to Framework Reaction
 
Js in quick books
Js in quick booksJs in quick books
Js in quick books
 
성공적인 서비스로의 플랫폼 선택
성공적인 서비스로의 플랫폼 선택성공적인 서비스로의 플랫폼 선택
성공적인 서비스로의 플랫폼 선택
 
Spring aop
Spring aopSpring aop
Spring aop
 
AWS RoadShow Manchester Part 3 - Getting Started with AWS
AWS RoadShow Manchester Part 3 - Getting Started with AWSAWS RoadShow Manchester Part 3 - Getting Started with AWS
AWS RoadShow Manchester Part 3 - Getting Started with AWS
 
AWS RoadShow Dublin - Part 3 Getting Started with AWS
AWS RoadShow Dublin - Part 3 Getting Started with AWSAWS RoadShow Dublin - Part 3 Getting Started with AWS
AWS RoadShow Dublin - Part 3 Getting Started with AWS
 
AWS RoadShow Cambridge Part 4 - Getting Started with AWS
AWS RoadShow Cambridge Part 4 - Getting Started with AWSAWS RoadShow Cambridge Part 4 - Getting Started with AWS
AWS RoadShow Cambridge Part 4 - Getting Started with AWS
 
AWS RoadShow Bristol - Part 2 Getting Started with AWS
AWS RoadShow Bristol - Part 2 Getting Started with AWSAWS RoadShow Bristol - Part 2 Getting Started with AWS
AWS RoadShow Bristol - Part 2 Getting Started with AWS
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

Spring AOP

  • 1. Spring AOPAspect Oriented Programming By SrinivasReddy.S www.java9s.com
  • 2. Cross Cutting Concerns class Bank{ private int balance; public void withdraw(int amount){ bankLogger.info(“Withdraw –”+amount); tx.begin(); balance = this.balance-amount; accountDao.saveBalance(balance); tx.commit(); } } www.java9s.com
  • 3. Cross Cutting Concerns Application Modules Application Modules Application Modules Application Modules Application Modules www.java9s.com
  • 4. Cross Cutting Concerns Logging Transaction Application Modules Application Modules Application Modules Spring Framework www.java9s.com
  • 5.
  • 13. AOP – Definitions. Logger Advice Advisor Method Method Method Joinpoints Advisor Transaction Manager www.java9s.com
  • 14. AOP - Definitions Advice defines what needs to be applied and when. Jointpoint is where the advice is applied. Pointcut is the combination of different joinpoints where the advice needs to be applied. Aspect is applying the Advice at the pointcuts. www.java9s.com
  • 15. Advice Types Before Advice After returning Advice Around Advice Throws Advice Method Method Method Method Exception www.java9s.com
  • 16. AOP - Weaving Compile time Class Load Time Runtime – Springs way Caller Target Proxy www.java9s.com
  • 17. Pointcut and Advisor POINTCUT CLASSES: Perl5RegexpMethodPointcut JdkRegexpMethodPointcut Pointcut and Advisor in one class: RegexpMethodPointcutAdvisor www.java9s.com
  • 18. Example public class CustomerImpl implements Customer{ public void browse(){ System.out.println("Browsing the internet"); } } class CafeOwner{ void LogInTime(){ System.out.println(“Log In time and name of the customer”); } void LogOutTime(){ System.out.println(“Log Out Time”); } void issueUsageBill(){ System.out.println(“Calculate and bill the customer”); } } www.java9s.com
  • 19. Before Advice -MethodBeforeAdvice class InternetAdvisor implements MethodBeforeAdvice{ private CafeOwner cafeOwner; public void before(Method arg0, Object[] arg1, Object arg2) throws Throwable { this.getCafeOwner().LogInTime(); } } www.java9s.com
  • 20. Customer Proxy Caller Target object CustomerImpl proxyInterface Customer RegexpMethodPointcutAdvisor “*” – Apply to all methods CafeOwner InternetAdvice implements MethodBeforeAdvice
  • 21. Configuration Step 1: Configure the Beans <bean id ="customerImpl" class ="CustomerImpl"/> <bean id = "cafeOwner" class ="CafeOwner"/> <bean id ="internetAdvice" class ="InternetAdvice"> <property name ="cafeOwner" ref ="cafeOwner"/> </bean> www.java9s.com
  • 22. Configuration Step 2: Configure the POINTCUT ADVISOR <bean id ="cafeOwnerBeforeAndAfterAdvice" class ="org.springframework.aop.support.RegexpMethodPointcutAdvisor"> <property name ="advice"> <ref local ="internetAdvice"/> </property> <property name ="pattern"> <value>.*</value> </property> </bean> www.java9s.com
  • 23. Configuration Step 3: Configure the ProxyFactoryBean <bean id ="customerProxy" class ="org.springframework.aop.framework.ProxyFactoryBean"> <property name ="target"> <ref local ="customerImpl"/> </property> <property name ="proxyInterfaces"> <value>Customer</value> </property> <property name ="interceptorNames"> <list> <value>cafeOwnerBeforeAndAfterAdvice</value> </list> </property> </bean> www.java9s.com
  • 24. Remember Spring Does not support AOP for Methods marked as final. Fields www.java9s.com