@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. 牛客HJ浇花。

    我也不知道这是什么类型的题,算是简单模拟吧.但是有个方法很赞. 开两个数组,一个模拟花,一个记录不同浇花次数花的数量: 要找浇水的次数,那么记每次浇水的开头和结尾就行了,a—b;那么f[a]++;f[ ...

  2. centos 端口开放及关闭 【转】

    之前有讲过公司新买的服务器使用的是CentOS 5.5,部署好Tomcat之后却发现输入114.80.*.*:8080(即ip:8080)却无法显示Tomcat默认的首页.因为以前部署在Win Ser ...

  3. Laravel学习--时间

    date("Y-m-d H:i:s"); list($usec, $sec) = explode(" ", microtime()); $time = (flo ...

  4. Java中动态获取项目根目录的绝对路径

    https://www.cnblogs.com/zhouqing/archive/2012/11/10/2757774.html 序言 在开发过程中经常会用到读写文件,其中就必然涉及路径问题.使用固定 ...

  5. root用户登录mysql后新建用户提示1045错误

    执行以下命令查看root权限 show grants for 'root'@'localhost'; 如果没有显示with grant option,说明是root没有拥有新建授权用户的权限(为什么会 ...

  6. linux日志管理

    //有关当前登录用户的信息记录在文件utmp中 //登录进入和退出纪录在文件wtmp中 [root@bogon python]# who //who命令查询utmp文件并报告当前登录的每个用户 /va ...

  7. python基础(六)——mysql的使用

    //验证是否安装mysqldb,这个是用于python连接mysql数据库的接口,而不是我们平时用的mysql import MySQLdb 安装MySQLdb,请访问 http://sourcefo ...

  8. getpwnam,getgrnam,getpwent,crypt等函数

    [root@bogon code]# cat a.c #include<stdio.h> #include<pwd.h> int main() { struct passwd ...

  9. MySQL--时间戳与时区问题

    对于使用 timestamp 的场景,MySQL 在访问 timestamp 字段时会做时区转换,当 time_zone 设置为 system 时,MySQL 访问每一行的 timestamp 字段时 ...

  10. pushpin Server-sent events && openresty 集成试用

    前边有写过一个简单pushpin 集成stream 的demo,这次测试下sse 的功能 备注: 环境依然使用的是docker-compose运行 环境准备 docker-compose 文件 ver ...