Spring AOP

AOP 原理

mapper

1 此处可以查看 mapper
2 org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator#postProcessAfterInitialization
3 org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator#wrapIfNecessary
4 org.springframework.aop.support.AopUtils#findAdvisorsThatCanApply

事务

 1Supplier afterCommit = () -> {
 2    executorService.execute(() -> {
 3        for (CreateHandlerWithContext<T> processor : afterCommitHandlerList) {
 4            try {
 5                processor.handle(t, context);
 6            } catch (Exception e) {
 7                e.printStackTrace();
 8                log.error("create observer after commit handle", e);
 9            }
10        }
11    });
12    return null;
13};
14
15if (TransactionSynchronizationManager.isActualTransactionActive()) {
16    //如果事务开启
17    TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
18        @Override
19        public void afterCommit() {
20            afterCommit.get();
21        }
22    });
23} else {
24    //如果事务没有开启
25    afterCommit.get();
26}

参考