在spring的tx源码中我们知道了,最后会通过AbstractAutoProxyCreator(其有一个父类是beanPostProcessor)的postProcessAfterInitialization(Object bean, String beanName)方法中的wrapIfNecessary方法去createProxy。
其中生成jdk动态代理的类是JdkDynamicAopProxy类,其proceed()方法会执行到ReflectiveMethodInvocation类的proceed()方法,最后如果是事务,会调用TransactionInterceptor类的invoke方法,这个方法实现自MethodInterceptor类,这个是MethodInterceptor并不是cglib的MethodInterceptor类,所以要分清楚,调用的是其invoke方法:
public Object invoke(final MethodInvocation invocation) throws Throwable {
// Work out the target class: may be <code>null</code>.
// The TransactionAttributeSource should be passed the target class
// as well as the method, which may be from an interface.
Class<?> targetClass = (invocation.getThis() != null ? AopUtils.getTargetClass(invocation.getThis()) : null);
// If the transaction attribute is null, the method is non-transactio