Spring Aop (Part 2)
How Spring Aop Works
Spring Aop is proxy based framework, a proxy object is created for the objects which are the target of an advice. Proxy which is an intermediate object is introduced by the spring aop framework between target and caller object. So when call to target object are made at runtime then its gets intercepted by proxy, which then executes the advice which apply to target method
So we can see here in above diagram that proxy is created for both Studentservice and Dataservice, which intercepts the call to method createstudnet and fetchstudent respectively. The proxy for student service will first execute log method of logging aspect followed by invocation of method createstudent. Similary the proxy for DataService will work.
So this is how Spring AOP solves the problem of cross-cutting concerns.
Note : Spring Aop gives the option to create AOP proxies via spring proxyFactoryBean or we can let spring to automatically create proxies. This automatic generation of aop proxies by spring aop is called as autoproxying.
You can check the code for proxyFactoyBean implementation here: https://github.com/satyapal1234/Spring-Aop/tree/main