Spring AOP
AOP is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. It does this by adding additional behavior to existing code without modifying the code itself.
Instead, we can declare the new code and the new behaviors separately.
In AOP, these concerns are encapsulated into aspects that can be applied across various parts of an application, reducing code duplication and improving maintainability.
What are cross-cutting concerns?
Cross-cutting concerns are aspects of a program that affect multiple components such as logging, security, transaction management, and exception handling.
What are the core concepts in Spring AOP?
- Aspect: A module that encapsulates a concern that cuts across multiple classes.
public class LogAfterReturnAspect {
private Logger logger = LoggerFactory.getLogger(this.getClass());
public void afterReturn(Object returnedValue) throws Throwable {
logger.info("Value return was {}", returnedValue);
}
}
- Joinpoint: is a point during the execution of a program, such as the execution of a method, or the handling of an exception.