In this Spring AOP Tutorial, We have lot of Examples of Creating Spring Aspect using annotation @Aspect, Declaring @Pointcut for Join Point and declaring different advice by using annotation based configuration @Before, @After, @Around annotations and also examples of XML-based or Schema based configuration. And also we will discuss about AOP Proxy.
What is AOP? AOP stands for Aspect Oriented Programming, It compliments OOPs in the different sense of concern, it also provides modularity. But in AOP the key unit of modularity is aspect than class and this aspects enable the modularization of concerns such as logging, security and transaction management. And these concerns cut across multiple types and objects in the application and these are commonly also known as crosscutting concerns of the application.
What are Cross-Cutting Concerns?
• Generic functionality that is needed in many places in your application
• Examples
– Logging and Tracing
– Transaction Management
– Security
– Caching
– Error Handling
– Performance Monitoring
– Custom Business Rules
System Without AOP or Modularization
There are two main problems – Code tangling
• A coupling of concerns – Code scattering
• The same concern spread across modules
System With AOP or Modularization
Aspect-Oriented Programming (AOP) enables modularization of cross-cutting concerns
– To avoid tangling
– To eliminate scattering
Core AOP Concepts
• Join Point
– A point in the execution of a program such as a method call or exception thrown
• Pointcut
– An expression that selects one or more Join Points
• Advice
– Code to be executed at each selected Join Point
• Aspect
– A module that encapsulates pointcuts and advice
• Weaving
– Technique by which aspects are combined with main code
Spring AOP Tutorial with Example
Read below examples to know more about implementing each advice in detail.
Spring AOP Interview Questions Top 20 Spring AOP Interview Questions and Answers
Some most asked spring AOP interview questions in java interviews. Spring AOP AspectJ Annotations and Java Based Configuration