Understanding AOP proxies
As you know that, Spring AOP is proxy-based. It mean Spring creates the proxy to weave the aspect between the business logic that is, in target
object. It is based on the Proxy and Decorator design pattern. Let's see TransferServiceImpl
class as an implementation of TransferService
interface:
package com.packt.patterninspring.chapter6.bankapp.service; import org.springframework.stereotype.Service; public class TransferServiceImpl implements TransferService { @Override public void transfer(String accountA, String accountB, Long amount) { System.out.println(amount+" Amount has been tranfered from "+accountA+" to "+accountB); } }
Caller invokes this service (transfer()
method) directly by the object reference, let's see the following figure to illustrate more:
As you can see that caller could directly call the service and do the task assigned to it.
But you declare this TransferService
as a target for the...