@Transactional标识类或方法,使方法被执行时使用事务方式执行,这里只讨论PROXY方法增强方法。使用@EnableTransactionManagement,默认model=AdviceMode.PROXY,通过@Import(TransactionManagementConfigurationSelector.class)来判断在加载时注册PROXY不是ASPECTJ相关类。PROXY相关类有AutoProxyRegistrar和ProxyTransactionManagementConfiguration。AutoProxyRegistrar作用是通过EnableTransactionManagement.proxyTargetClass值判断使用CGLIB或是Java interface-based proxies。使用Java interface-based proxies时AnnotationAwareAspectJAutoProxyCreator,AnnotationAwareAspectJAutoProxyCreator是一个BeanPostProcessor实现类。使用CGLIB也是注册AnnotationAwareAspectJAutoProxyCreator并且将proxyTargetClass=true,如下AopConfigUtils.forceAutoProxyCreatorToUseClassProxying()
 

AnnotationAwareAspectJAutoProxyCreator.wrapIfNecessary()

AnnotationAwareAspectJAutoProxyCreator是一个BeanPostProcessor实现类,它的相应方法会在容器管理每个对象实例化不同阶段会执行。wrapIfNecessary()方法在postProcessAfterInitialization()方法调用,主要是判断实例化对象是否容器所有Advisor所要作用对象,如@Transactional标识的方法或类的对象匹配BeanFactoryTransactionAttributeSourceAdvisor。
 
AnnotationTransactionAttributeSource.determineTransactionAttribute()
判断传入的方法是否含@Transactional标识,返回TransactionAttribute
下面是AnnotationAwareAspectJAutoProxyCreator(AbstractAutoProxyCreator).wrapIfNecessary()的stack
Thread [main] (Suspended (breakpoint at line 348 in AbstractAutoProxyCreator))    
    owns: ConcurrentHashMap<K,V>  (id=2343)    
    owns: Object  (id=2107)    
    AnnotationAwareAspectJAutoProxyCreator(AbstractAutoProxyCreator).wrapIfNecessary(Object, String, Object) line: 348    
    AnnotationAwareAspectJAutoProxyCreator(AbstractAutoProxyCreator).postProcessAfterInitialization(Object, String) line: 298    
    DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).applyBeanPostProcessorsAfterInitialization(Object, String) line: 435    
    DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).initializeBean(String, Object, RootBeanDefinition) line: 1721    
    DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).doCreateBean(String, RootBeanDefinition, Object[]) line: 581    
    DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).createBean(String, RootBeanDefinition, Object[]) line: 498    
    DefaultListableBeanFactory(AbstractBeanFactory).lambda$doGetBean$0(String, RootBeanDefinition, Object[]) line: 305    
    48361312.getObject() line: not available    
    DefaultListableBeanFactory(DefaultSingletonBeanRegistry).getSingleton(String, ObjectFactory<?>) line: 233    
    DefaultListableBeanFactory(AbstractBeanFactory).doGetBean(String, Class<T>, Object[], boolean) line: 303    
    DefaultListableBeanFactory(AbstractBeanFactory).getBean(String, Class<T>) line: 198    
    CommonAnnotationBeanPostProcessor.autowireResource(BeanFactory, CommonAnnotationBeanPostProcessor$LookupElement, String) line: 512    
    CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor$LookupElement, String) line: 483    
    CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(Object, String) line: 617    
    CommonAnnotationBeanPostProcessor$ResourceElement(InjectionMetadata$InjectedElement).inject(Object, String, PropertyValues) line: 172    
    InjectionMetadata.inject(Object, String, PropertyValues) line: 89    
    CommonAnnotationBeanPostProcessor.postProcessPropertyValues(PropertyValues, PropertyDescriptor[], Object, String) line: 317    
    DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).populateBean(String, RootBeanDefinition, BeanWrapper) line: 1353    
    DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).doCreateBean(String, RootBeanDefinition, Object[]) line: 579    
    DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).createBean(String, RootBeanDefinition, Object[]) line: 498    
    DefaultListableBeanFactory(AbstractBeanFactory).lambda$doGetBean$0(String, RootBeanDefinition, Object[]) line: 305    
    48361312.getObject() line: not available    
    DefaultListableBeanFactory(DefaultSingletonBeanRegistry).getSingleton(String, ObjectFactory<?>) line: 233    
    DefaultListableBeanFactory(AbstractBeanFactory).doGetBean(String, Class<T>, Object[], boolean) line: 303    
    DefaultListableBeanFactory(AbstractBeanFactory).getBean(String, Class<T>) line: 198    
    CommonAnnotationBeanPostProcessor.autowireResource(BeanFactory, CommonAnnotationBeanPostProcessor$LookupElement, String) line: 512    
    CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor$LookupElement, String) line: 483    
    CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(Object, String) line: 617    
    CommonAnnotationBeanPostProcessor$ResourceElement(InjectionMetadata$InjectedElement).inject(Object, String, PropertyValues) line: 172    
    InjectionMetadata.inject(Object, String, PropertyValues) line: 89    
    CommonAnnotationBeanPostProcessor.postProcessPropertyValues(PropertyValues, PropertyDescriptor[], Object, String) line: 317    
    DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).populateBean(String, RootBeanDefinition, BeanWrapper) line: 1353    
    DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).doCreateBean(String, RootBeanDefinition, Object[]) line: 579    
    DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).createBean(String, RootBeanDefinition, Object[]) line: 498    
    DefaultListableBeanFactory(AbstractBeanFactory).lambda$doGetBean$0(String, RootBeanDefinition, Object[]) line: 305    
    48361312.getObject() line: not available    
    DefaultListableBeanFactory(DefaultSingletonBeanRegistry).getSingleton(String, ObjectFactory<?>) line: 233    
    DefaultListableBeanFactory(AbstractBeanFactory).doGetBean(String, Class<T>, Object[], boolean) line: 303    
    DefaultListableBeanFactory(AbstractBeanFactory).getBean(String) line: 193    
    DefaultListableBeanFactory.preInstantiateSingletons() line: 747    
    AnnotationConfigApplicationContext(AbstractApplicationContext).finishBeanFactoryInitialization(ConfigurableListableBeanFactory) line: 861    
    AnnotationConfigApplicationContext(AbstractApplicationContext).refresh() line: 542    
    SpringApplication.refresh(ApplicationContext) line: 750    
    SpringApplication.refreshContext(ConfigurableApplicationContext) line: 386    
    SpringApplication.run(String...) line: 327    
    SpringApplication.run(Class<?>[], String[]) line: 1245    
    SpringApplication.run(Class<?>, String...) line: 1233    
    Application.main(String[]) line: 56    
如果对象是Advisor所要作用对象,则调用createProxy()生成proxy对象封闭目标对象,增强目标对象。如下面stack
Thread [main] (Suspended (breakpoint at line 441 in AbstractAutoProxyCreator))    
    owns: ConcurrentHashMap<K,V>  (id=2343)    
    owns: Object  (id=2107)    
    AnnotationAwareAspectJAutoProxyCreator(AbstractAutoProxyCreator).createProxy(Class<?>, String, Object[], TargetSource) line: 441    
    AnnotationAwareAspectJAutoProxyCreator(AbstractAutoProxyCreator).wrapIfNecessary(Object, String, Object) line: 349    
    AnnotationAwareAspectJAutoProxyCreator(AbstractAutoProxyCreator).postProcessAfterInitialization(Object, String) line: 298    
    DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).applyBeanPostProcessorsAfterInitialization(Object, String) line: 435    
    DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).initializeBean(String, Object, RootBeanDefinition) line: 1721    
    DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).doCreateBean(String, RootBeanDefinition, Object[]) line: 581    
    DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).createBean(String, RootBeanDefinition, Object[]) line: 498    
    DefaultListableBeanFactory(AbstractBeanFactory).lambda$doGetBean$0(String, RootBeanDefinition, Object[]) line: 305    
    48361312.getObject() line: not available    
    DefaultListableBeanFactory(DefaultSingletonBeanRegistry).getSingleton(String, ObjectFactory<?>) line: 233    
    DefaultListableBeanFactory(AbstractBeanFactory).doGetBean(String, Class<T>, Object[], boolean) line: 303    
    DefaultListableBeanFactory(AbstractBeanFactory).getBean(String, Class<T>) line: 198    
    CommonAnnotationBeanPostProcessor.autowireResource(BeanFactory, CommonAnnotationBeanPostProcessor$LookupElement, String) line: 512    
    CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor$LookupElement, String) line: 483    
    CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(Object, String) line: 617    
    CommonAnnotationBeanPostProcessor$ResourceElement(InjectionMetadata$InjectedElement).inject(Object, String, PropertyValues) line: 172    
    InjectionMetadata.inject(Object, String, PropertyValues) line: 89    
    CommonAnnotationBeanPostProcessor.postProcessPropertyValues(PropertyValues, PropertyDescriptor[], Object, String) line: 317    
    DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).populateBean(String, RootBeanDefinition, BeanWrapper) line: 1353    
    DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).doCreateBean(String, RootBeanDefinition, Object[]) line: 579    
    DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).createBean(String, RootBeanDefinition, Object[]) line: 498    
    DefaultListableBeanFactory(AbstractBeanFactory).lambda$doGetBean$0(String, RootBeanDefinition, Object[]) line: 305    
    48361312.getObject() line: not available    
    DefaultListableBeanFactory(DefaultSingletonBeanRegistry).getSingleton(String, ObjectFactory<?>) line: 233    
    DefaultListableBeanFactory(AbstractBeanFactory).doGetBean(String, Class<T>, Object[], boolean) line: 303    
    DefaultListableBeanFactory(AbstractBeanFactory).getBean(String, Class<T>) line: 198    
    CommonAnnotationBeanPostProcessor.autowireResource(BeanFactory, CommonAnnotationBeanPostProcessor$LookupElement, String) line: 512    
    CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor$LookupElement, String) line: 483    
    CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(Object, String) line: 617    
    CommonAnnotationBeanPostProcessor$ResourceElement(InjectionMetadata$InjectedElement).inject(Object, String, PropertyValues) line: 172    
    InjectionMetadata.inject(Object, String, PropertyValues) line: 89    
    CommonAnnotationBeanPostProcessor.postProcessPropertyValues(PropertyValues, PropertyDescriptor[], Object, String) line: 317    
    DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).populateBean(String, RootBeanDefinition, BeanWrapper) line: 1353    
    DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).doCreateBean(String, RootBeanDefinition, Object[]) line: 579    
    DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).createBean(String, RootBeanDefinition, Object[]) line: 498    
    DefaultListableBeanFactory(AbstractBeanFactory).lambda$doGetBean$0(String, RootBeanDefinition, Object[]) line: 305    
    48361312.getObject() line: not available    
    DefaultListableBeanFactory(DefaultSingletonBeanRegistry).getSingleton(String, ObjectFactory<?>) line: 233    
    DefaultListableBeanFactory(AbstractBeanFactory).doGetBean(String, Class<T>, Object[], boolean) line: 303    
    DefaultListableBeanFactory(AbstractBeanFactory).getBean(String) line: 193    
    DefaultListableBeanFactory.preInstantiateSingletons() line: 747    
    AnnotationConfigApplicationContext(AbstractApplicationContext).finishBeanFactoryInitialization(ConfigurableListableBeanFactory) line: 861    
    AnnotationConfigApplicationContext(AbstractApplicationContext).refresh() line: 542    
    SpringApplication.refresh(ApplicationContext) line: 750    
    SpringApplication.refreshContext(ConfigurableApplicationContext) line: 386    
    SpringApplication.run(String...) line: 327    
    SpringApplication.run(Class<?>[], String[]) line: 1245    
    SpringApplication.run(Class<?>, String...) line: 1233    
    Application.main(String[]) line: 56    
 

AbstractAutoProxyCreator.createProxy()

DefaultAopProxyFactory.createAopProxy()
@Transactional标识增强对象是类所以创建proxy对象是ObjenesisCglibAopProxy
 
 
 

Spring-framework应用程序启动loadtime源码分析笔记(二)——@Transactional的更多相关文章

  1. Spring-framework应用程序启动loadtime源码分析笔记(一)

    1,实例化DefaultListableBeanFactory DefaultListableBeanFactory是AnnotationConfigApplicationContext的组件,Def ...

  2. Spring-framework应用程序启动loadtime源码分析笔记(三)——@KafkaListener

    org.springframework.context.annotation.ConfigurationClassParser.getConfigurationClasses()读所有@Configu ...

  3. 涨姿势:Spring Boot 2.x 启动全过程源码分析

    目录 SpringApplication 实例 run 方法运行过程 总结 上篇<Spring Boot 2.x 启动全过程源码分析(一)入口类剖析>我们分析了 Spring Boot 入 ...

  4. Spring Boot 2.x 启动全过程源码分析

    Spring Boot 2.x 启动全过程源码分析 SpringApplication 实例 run 方法运行过程 上面分析了 SpringApplication 实例对象构造方法初始化过程,下面继续 ...

  5. Spring Boot 2.x 启动全过程源码分析(上)入口类剖析

    Spring Boot 的应用教程我们已经分享过很多了,今天来通过源码来分析下它的启动过程,探究下 Spring Boot 为什么这么简便的奥秘. 本篇基于 Spring Boot 2.0.3 版本进 ...

  6. Spring Boot Dubbo 应用启停源码分析

    作者:张乎兴 来源:Dubbo官方博客 背景介绍 Dubbo Spring Boot 工程致力于简化 Dubbo | grep tid | grep -v "daemon" tid ...

  7. Spring第四天,BeanPostProcessor源码分析,彻底搞懂IOC注入及注解优先级问题!

  8. worker启动executor源码分析-executor.clj

    在"supervisor启动worker源码分析-worker.clj"一文中,我们详细讲解了worker是如何初始化的.主要通过调用mk-worker函数实现的.在启动worke ...

  9. supervisor启动worker源码分析-worker.clj

    supervisor通过调用sync-processes函数来启动worker,关于sync-processes函数的详细分析请参见"storm启动supervisor源码分析-superv ...

随机推荐

  1. 线段树专题2-(加强版线段树-可持续化线段树)主席树 orz! ------用于解决区间第k大的问题----xdoj-1216

    poj-2104(区间第K大问题) #include <iostream> #include <algorithm> #include <cstdio> #incl ...

  2. Formal Grammars of English -10 chapter(Speech and Language Processing)

    determiner  限定词 DET propernoun 专有名词 NP (or noun phrase) mass noun 不可数名词 Det Nouns 限定词名词 relative pro ...

  3. BZOJ 2002:Bounce 弹飞绵羊(分块)

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec  Memory Limit: 259 MB Submit: 14944  Solved: 7598 [Su ...

  4. 项目报错 exception 'MongoConnectionException' with message 'Failed to connect to: 127.0.0.1:27017: Authentication failed on database 'www' with username 'www': auth failed' in

    出现这个错误,在官方文档也找到了解释,原来在2.6版本做了很大的改进,其改进涉及到核心.存储.网络.查询和安全性等多方面,自然,其用户登录认证机制也发生了改变,db.system.users的sche ...

  5. HDU 1000

    A + B Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...

  6. plsql developer 使用sys用户登录,报ORA-01031权限不足,解决sys(dba权限用户)远程登录报错。

    数据库服务器架设在机器A上,此时我在机器B上进行远程连接,使用sys账号远程登录时报ORA-01031:insufficient privileges 或 ORA-01017: invalid use ...

  7. Sencha Touch app example -- oreilly app 分析

    from: 2013/8/30的笔记 使用development.js 读取 app.json 配置文件 app.json 配置了app.js文件 app.js lauch function ,首先用 ...

  8. 【JVM】内存分析<一>工具的使用

    一. 获取堆快照 1.出现OOME时生成堆dump: #出现 OOME 时生成堆 dump: -XX:+HeapDumpOnOutOfMemoryError #生成堆文件地址: -XX:HeapDum ...

  9. Jenkins部署项目

    第三首先部署好Jenkins 新建一个自由项目 svn地址,credentials是指认证,点击Ad那里添加,并选择username和password方式,并输入用户名和密码 H/5 * * * * ...

  10. <---------------线程修改名字、得到名字及开启------------------>

    ThreadDemo: public class ThreadDemo extends Thread { public void run(){ System.out.println(getName() ...