Spring AOP Self-Invocation Problem and a Kotlinic Workaround

Spring AOP Problem In Spring, self-invocation refers to a method within a class calling another method of the same class. This can be problematic when using AOP (Aspect-Oriented Programming) annotations like @Transactional. Spring AOP is proxy-based. So if you call another method directly within the same class, it bypasses the proxy, and AOP annotations won’t be applied. For example, suppose you have method A annotated with @Transactional, and it’s called from method B in the same class. If method B calls A directly, Spring won’t manage the transaction properly because the call doesn’t go through the proxy. ...

May 27, 2024

Logging AOP Implementation - 1

Introduction Logging is not code for handling business logic, but rather for monitoring. That’s why logging appearing in the middle of business logic is very uncomfortable to see. Spring provides AOP, but I wanted to try implementing it myself without looking at Spring’s implementation. So, this time, I want to think about how to implement a great logging AOP. Situation Let’s write a sayHello method in the Person class and call it from main. Here, let’s assume the person object is provided by a framework. ...

September 19, 2021