sxd-spring-aop-12启动概要
2023-03-10 14:18:50 6 举报
AI智能生成
sxd-spring启动概要
作者其他创作
大纲/内容
xml
注解
AnnotationConfigApplicationContext
this()
new AnnotatedBeanDefinitionReader
new ConditionContextImpl
registerAnnotationConfigProcessors
AnnotationAwareOrderComparator
ContextAnnotationAutowireCandidateResolver
ConfigurationClassPostProcessor
AutowiredAnnotationBeanPostProcessor
CommonAnnotationBeanPostProcessor<br>
PersistenceAnnotationBeanPostProcessor
EventListenerMethodProcessor
DefaultEventListenerFactory
new ClassPathBeanDefinitionScanner
registerDefaultFilters
Component
ManagedBean
Named
register(componentClasses)
new AnnotatedGenericBeanDefinition
refresh()
prepareBeanFactory
ApplicationContextAwareProcessor
ApplicationListenerDetector
EnvironmentAware
EmbeddedValueResolverAware
ResourceLoaderAware
ApplicationEventPublisherAware
MessageSourceAware
ApplicationContextAware
invokeBeanFactoryPostProcessors<br>
BeanDefinitionRegistryPostProcessor
# postProcessBeanDefinitionRegistry
ConfigurationClassPostProcessor
new ConfigurationClassParser
ConfigurationClassParser#parse
ComponentScanAnnotationParser#parse
new ClassPathBeanDefinitionScanner # doScan
new ScannedGenericBeanDefinition
loadBeanDefinitions
processImports
AnnotationAwareAspectJAutoProxyCreator<br>
TransactionManagementConfigurationSelector<br>
AutoProxyRegistrar<br>
ProxyTransactionManagementConfiguration<br>
loadBeanDefinitionsForConfigurationClass
ImportAwareBeanPostProcessor
BeanFactoryPostProcessor
# postProcessBeanFactory<br>
ApplicationListenerDetector
finishBeanFactoryInitialization
getBean -> doGetBean -> createBean
resolveBeforeInstantiation
applyBeanPostProcessorsBeforeInstantiation
InstantiationAwareBeanPostProcessor
ConfigurationClassPostProcessor -》 ImportAwareBeanPostProcessor<br>
CommonAnnotationBeanPostProcessor
AutowiredAnnotationBeanPostProcessor
AspectJAwareAdvisorAutoProxyCreator
applyBeanPostProcessorsAfterInitialization
InstantiationAwareBeanPostProcessor
ConfigurationClassPostProcessor -》 ImportAwareBeanPostProcessor
CommonAnnotationBeanPostProcessor
AutowiredAnnotationBeanPostProcessor
doCreateBean
applyMergedBeanDefinitionPostProcessors
MergedBeanDefinitionPostProcessor
CommonAnnotationBeanPostProcessor
AutowiredAnnotationBeanPostProcessor
ApplicationListenerDetector
createBeanInstance
populateBean
postProcessAfterInstantiation<br>
InstantiationAwareBeanPostProcessor
ConfigurationClassPostProcessor -》 ImportAwareBeanPostProcessor
CommonAnnotationBeanPostProcessor
AutowiredAnnotationBeanPostProcessor<br>
postProcessProperties
InstantiationAwareBeanPostProcessor
ConfigurationClassPostProcessor -》 ImportAwareBeanPostProcessor
CommonAnnotationBeanPostProcessor
AutowiredAnnotationBeanPostProcessor<br>
initializeBean
invokeAwareMethods
BeanNameAware
BeanClassLoaderAware
BeanFactoryAware
applyBeanPostProcessorsBeforeInitialization
postProcessBeforeInitialization
BeanPostProcessor
ApplicationContextAwareProcessor
EnvironmentAware
EmbeddedValueResolverAware
ResourceLoaderAware
ApplicationEventPublisherAware
MessageSourceAware
ApplicationContextAware
ConfigurationClassPostProcessor -》 ImportAwareBeanPostProcessor
ImportAware
PostProcessorRegistrationDelegate -> BeanPostProcessorChecker
CommonAnnotationBeanPostProcessor
InstantiationAwareBeanPostProcessorAdapter -> AutowiredAnnotationBeanPostProcessor
ApplicationListenerDetector
invokeInitMethods
applyBeanPostProcessorsAfterInitialization
postProcessAfterInitialization
BeanPostProcessor
ApplicationContextAwareProcessor
ConfigurationClassPostProcessor -》 ImportAwareBeanPostProcessor
PostProcessorRegistrationDelegate -> BeanPostProcessorChecker
CommonAnnotationBeanPostProcessor
InstantiationAwareBeanPostProcessorAdapter -> AutowiredAnnotationBeanPostProcessor
ApplicationListenerDetector
AnnotationAwareAspectJAutoProxyCreator
aop
xml 执行流程
ConfigBeanDefinitionParser#parse<br>parseAspect<br>加载bd<br>
configureAutoProxyCreator
AspectJAwareAdvisorAutoProxyCreator
aspectElement.getChildNodes()
parseAdvice <br>aop:around<br>aop: before<br>aop:after<br>aop: returning<br>aop: afterThrowing
aspectFactoryDef -> MethodLocatingFactoryBean
methodDefinition-> SimpleBeanFactoryAwareAspectInstanceFactory
createAdviceDefinition
AspectJAroundAdvice
AspectJMethodBeforeAdvice<br>
AspectJAfterAdvice
AspectJAfterReturningAdvice
AspectJAfterThrowingAdvice
new RootBeanDefinition(AspectJPointcutAdvisor
AspectJPointcutAdvisor
parsePointcut
new RootBeanDefinition(AspectJExpressionPointcut.class)
AspectJExpressionPointcut<br>
创建bean
createBean()<br># 非Spring内置对象
resolveBeforeInstantiation<br>创建对象前置时创建所有的advisor
# shouldSkip
AspectJPointcutAdvisor
doCreateBean
initializeBean
applyBeanPostProcessorsAfterInitialization
wrapIfNecessary
findEligibleAdvisors # extendxxx
ExposeInvocationInterceptor
getCallbacks
StaticUnadvisedInterceptor
DynamicUnadvisedInterceptor
执行
CglibAopProxy.DynamicAdvisedInterceptor#intercept
this.advised.getInterceptorsAndDynamicInterceptionAdvice(method, targetClass)
new CglibMethodInvocation(proxy, target, method, args, targetClass, chain, methodProxy).proceed()
ReflectiveMethodInvocation#proceed<br>执行父类的方法
Object interceptorOrInterceptionAdvice =<br> this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
1: ExposeInvocationInterceptor<br>
((MethodInterceptor) interceptorOrInterceptionAdvice).invoke(this)
mi.proceed();
Object interceptorOrInterceptionAdvice =<br> this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
2:AspectjAfterThrowingAdvice<br>
try { mi.proceed();
catch -》 invokeAdviceMethod(getJoinPointMatch(), null, ex);
Object interceptorOrInterceptionAdvice =<br> this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
3: AfterRunturningAdviceInterceptor<br>
mi.proceed();
this.advice.afterReturning(retVal, mi.getMethod(), mi.getArguments(), mi.getThis());
Object interceptorOrInterceptionAdvice =<br> this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
4: AspectAfterAdvice
mi.proceed();
invokeAdviceMethod(getJoinPointMatch(), null, null);
invokeAdviceMethodWithGivenArgs(argBinding(jp, jpMatch, returnValue, t)
argBinding
invokeAdviceMethodWithGivenArgs
this.aspectJAdviceMethod.invoke(this.aspectInstanceFactory.getAspectInstance(), actualArgs)
Object interceptorOrInterceptionAdvice =<br> this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
5: AspectARoundAdvice
ProceedingJoinPoint pjp = lazyGetProceedingJoinPoint(pmi);
JoinPointMatch jpm = getJoinPointMatch(pmi);
invokeAdviceMethod(pjp, jpm, null, null)
注解执行流程
加载bd
ConfigurationClassPostProcessor#processConfigBeanDefinitions
AnnotationAwareAspectJAutoProxyCreator<br>
TransactionManagementConfigurationSelector<br>
AutoProxyRegistrar<br>
ProxyTransactionManagementConfiguration<br>
创建bean
createBean()<br># 非Spring内置对象
resolveBeforeInstantiation<br>创建对象前置时创建所有的advisor
# shouldSkip
AnnotationAwareAspectJAutoProxyCreator#buildAspectJAdvisors()
advisorFactory.getAdvisors
for -> getAdvisorMethods(aspectClass)<br>拿到当前类的所有方法遍历
getAdvisor
new AspectJExpressionPointcut
new InstantiationModelAwarePointcutAdvisorImpl
doCreateBean
initializeBean
applyBeanPostProcessorsAfterInitialization
wrapIfNecessary
findEligibleAdvisors # extendxxx
ExposeInvocationInterceptor
getCallbacks
StaticUnadvisedInterceptor
DynamicUnadvisedInterceptor
执行
aop:事务
xml执行流程
加载bd
configureAutoProxyCreator
AspectJAwareAdvisorAutoProxyCreator
parsePointcut
AspectJExpressionPointcut
parseAdvisor
DefaultBeanFactoryPointcutAdvisor
tx:advice<br>
TransactionInterceptor<br>
parseAttributeSource<br>
创建bean
createBean()<br># 非Spring内置对象
resolveBeforeInstantiation<br>创建对象前置时创建所有的advisor
# shouldSkip
DefaultBeanFactoryPointcutAdvisor
doCreateBean
initializeBean
applyBeanPostProcessorsAfterInitialization
wrapIfNecessary
findEligibleAdvisors # extendxxx
ExposeInvocationInterceptor
getCallbacks
StaticUnadvisedInterceptor
DynamicUnadvisedInterceptor
CglibAopProxy.DynamicAdvisedInterceptor#intercept
this.advised.getInterceptorsAndDynamicInterceptionAdvice(method, targetClass)
new CglibMethodInvocation(proxy, target, method, args, targetClass, chain, methodProxy).proceed()
ReflectiveMethodInvocation#proceed<br>执行父类的方法
Object interceptorOrInterceptionAdvice =<br> this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
1: ExposeInvocationInterceptor<br>
((MethodInterceptor) interceptorOrInterceptionAdvice).invoke(this)
mi.proceed();
Object interceptorOrInterceptionAdvice =<br> this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
2. TransactionInterceptor<br>
invokeWithinTransaction
getTransactionAttributeSource()
TransactionAttributeSource
tas.getTransactionAttribute
determineTransactionManager
TransactionManager
asPlatformTransactionManager
PlatformTransactionManager
methodIdentification
createTransactionIfNecessary
tm.getTransaction(txAttr)<br>
TransactionDefinition def
doGetTransaction()<br>DataSourceTransactionObject<br>
DataSourceTransactionObject
isExistingTransaction
def.getTimeout
suspend(null)
startTransaction
newTransactionStatus<br>
DefaultTransactionStatus
doBegin
obtainDataSource().getConnection()<br># DruidDataSource 不往下看了<br>
txObject.setConnectionHolder(new ConnectionHolder(newCon), true);
txObject.getConnectionHolder().setSynchronizedWithTransaction(true);
txObject.setPreviousIsolationLevel(previousIsolationLevel);
txObject.setMustRestoreAutoCommit(true);
con.setAutoCommit(false);
txObject.getConnectionHolder().setTransactionActive(true);
determineTimeout
TransactionSynchronizationManager.bindResource
prepareSynchronization
prepareTransactionInfo
invocation.proceedWithInvocation()
completeTransactionAfterThrowing(txInfo, ex)
cleanupTransactionInfo(txInfo);
commitTransactionAfterReturning
txInfo.getTransactionManager().commit
defStatus.isLocalRollbackOnly()
processRollback(defStatus, false)
defStatus.isGlobalRollbackOnly()
processRollback(defStatus, true);
processCommit(defStatus)
注解执行流程
0 条评论
下一页