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
PersistenceAnnotationBeanPostProcessor
EventListenerMethodProcessor
DefaultEventListenerFactory
new ClassPathBeanDefinitionScanner
registerDefaultFilters
Component
ManagedBean
Named
register(componentClasses)
new AnnotatedGenericBeanDefinition
refresh()
prepareBeanFactory
ApplicationContextAwareProcessor
ApplicationListenerDetector
EnvironmentAware
EmbeddedValueResolverAware
ResourceLoaderAware
ApplicationEventPublisherAware
MessageSourceAware
ApplicationContextAware
invokeBeanFactoryPostProcessors
BeanDefinitionRegistryPostProcessor
# postProcessBeanDefinitionRegistry
ConfigurationClassPostProcessor
new ConfigurationClassParser
ConfigurationClassParser#parse
ComponentScanAnnotationParser#parse
new ClassPathBeanDefinitionScanner # doScan
new ScannedGenericBeanDefinition
loadBeanDefinitions
processImports
AnnotationAwareAspectJAutoProxyCreator
TransactionManagementConfigurationSelector
AutoProxyRegistrar
ProxyTransactionManagementConfiguration
loadBeanDefinitionsForConfigurationClass
ImportAwareBeanPostProcessor
BeanFactoryPostProcessor
# postProcessBeanFactory
ApplicationListenerDetector
finishBeanFactoryInitialization
getBean -> doGetBean -> createBean
resolveBeforeInstantiation
applyBeanPostProcessorsBeforeInstantiation
InstantiationAwareBeanPostProcessor
ConfigurationClassPostProcessor -》 ImportAwareBeanPostProcessor
CommonAnnotationBeanPostProcessor
AutowiredAnnotationBeanPostProcessor
AspectJAwareAdvisorAutoProxyCreator
applyBeanPostProcessorsAfterInitialization
InstantiationAwareBeanPostProcessor
ConfigurationClassPostProcessor -》 ImportAwareBeanPostProcessor
CommonAnnotationBeanPostProcessor
AutowiredAnnotationBeanPostProcessor
doCreateBean
applyMergedBeanDefinitionPostProcessors
MergedBeanDefinitionPostProcessor
CommonAnnotationBeanPostProcessor
AutowiredAnnotationBeanPostProcessor
ApplicationListenerDetector
createBeanInstance
populateBean
postProcessAfterInstantiation
InstantiationAwareBeanPostProcessor
ConfigurationClassPostProcessor -》 ImportAwareBeanPostProcessor
CommonAnnotationBeanPostProcessor
AutowiredAnnotationBeanPostProcessor
postProcessProperties
InstantiationAwareBeanPostProcessor
ConfigurationClassPostProcessor -》 ImportAwareBeanPostProcessor
CommonAnnotationBeanPostProcessor
AutowiredAnnotationBeanPostProcessor
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
parseAspect
加载bd
parseAspect
加载bd
configureAutoProxyCreator
AspectJAwareAdvisorAutoProxyCreator
aspectElement.getChildNodes()
parseAdvice
aop:around
aop: before
aop:after
aop: returning
aop: afterThrowing
aop:around
aop: before
aop:after
aop: returning
aop: afterThrowing
aspectFactoryDef -> MethodLocatingFactoryBean
methodDefinition-> SimpleBeanFactoryAwareAspectInstanceFactory
createAdviceDefinition
AspectJAroundAdvice
AspectJMethodBeforeAdvice
AspectJAfterAdvice
AspectJAfterReturningAdvice
AspectJAfterThrowingAdvice
new RootBeanDefinition(AspectJPointcutAdvisor
AspectJPointcutAdvisor
parsePointcut
new RootBeanDefinition(AspectJExpressionPointcut.class)
AspectJExpressionPointcut
创建bean
createBean()
# 非Spring内置对象
# 非Spring内置对象
resolveBeforeInstantiation
创建对象前置时创建所有的advisor
创建对象前置时创建所有的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
执行父类的方法
执行父类的方法
Object interceptorOrInterceptionAdvice =
this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
1: ExposeInvocationInterceptor
((MethodInterceptor) interceptorOrInterceptionAdvice).invoke(this)
mi.proceed();
Object interceptorOrInterceptionAdvice =
this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
2:AspectjAfterThrowingAdvice
try { mi.proceed();
catch -》 invokeAdviceMethod(getJoinPointMatch(), null, ex);
Object interceptorOrInterceptionAdvice =
this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
3: AfterRunturningAdviceInterceptor
mi.proceed();
this.advice.afterReturning(retVal, mi.getMethod(), mi.getArguments(), mi.getThis());
Object interceptorOrInterceptionAdvice =
this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
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 =
this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
5: AspectARoundAdvice
ProceedingJoinPoint pjp = lazyGetProceedingJoinPoint(pmi);
JoinPointMatch jpm = getJoinPointMatch(pmi);
invokeAdviceMethod(pjp, jpm, null, null)
注解执行流程
加载bd
ConfigurationClassPostProcessor#processConfigBeanDefinitions
AnnotationAwareAspectJAutoProxyCreator
TransactionManagementConfigurationSelector
AutoProxyRegistrar
ProxyTransactionManagementConfiguration
创建bean
createBean()
# 非Spring内置对象
# 非Spring内置对象
resolveBeforeInstantiation
创建对象前置时创建所有的advisor
创建对象前置时创建所有的advisor
# shouldSkip
AnnotationAwareAspectJAutoProxyCreator#buildAspectJAdvisors()
advisorFactory.getAdvisors
for -> getAdvisorMethods(aspectClass)
拿到当前类的所有方法遍历
拿到当前类的所有方法遍历
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
TransactionInterceptor
parseAttributeSource
创建bean
createBean()
# 非Spring内置对象
# 非Spring内置对象
resolveBeforeInstantiation
创建对象前置时创建所有的advisor
创建对象前置时创建所有的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
执行父类的方法
执行父类的方法
Object interceptorOrInterceptionAdvice =
this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
1: ExposeInvocationInterceptor
((MethodInterceptor) interceptorOrInterceptionAdvice).invoke(this)
mi.proceed();
Object interceptorOrInterceptionAdvice =
this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
2. TransactionInterceptor
invokeWithinTransaction
getTransactionAttributeSource()
TransactionAttributeSource
tas.getTransactionAttribute
determineTransactionManager
TransactionManager
asPlatformTransactionManager
PlatformTransactionManager
methodIdentification
createTransactionIfNecessary
tm.getTransaction(txAttr)
TransactionDefinition def
doGetTransaction()
DataSourceTransactionObject
DataSourceTransactionObject
DataSourceTransactionObject
isExistingTransaction
def.getTimeout
suspend(null)
startTransaction
newTransactionStatus
DefaultTransactionStatus
doBegin
obtainDataSource().getConnection()
# DruidDataSource 不往下看了
# DruidDataSource 不往下看了
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 条评论
下一页