springAOP分析
参考https://www.cnblogs.com/liuyk-code/p/9886033.html
在springboot中自动引入了配置文件AopAutoConfiguration
@Configuration
@ConditionalOnClass({ EnableAspectJAutoProxy.class, Aspect.class, Advice.class,
AnnotatedElement.class })
@ConditionalOnProperty(prefix = "spring.aop", name = "auto", havingValue = "true", matchIfMissing = true)
public class AopAutoConfiguration { @Configuration
@EnableAspectJAutoProxy(proxyTargetClass = false)
@ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "false", matchIfMissing = false)
public static class JdkDynamicAutoProxyConfiguration { } @Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true)
@ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "true", matchIfMissing = true)
public static class CglibAutoProxyConfiguration { } }
满足条件的时候有引入了EnableAspectJAutoProxy
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import(AspectJAutoProxyRegistrar.class)
public @interface EnableAspectJAutoProxy { /**
* Indicate whether subclass-based (CGLIB) proxies are to be created as opposed
* to standard Java interface-based proxies. The default is {@code false}.
*/
boolean proxyTargetClass() default false; /**
* Indicate that the proxy should be exposed by the AOP framework as a {@code ThreadLocal}
* for retrieval via the {@link org.springframework.aop.framework.AopContext} class.
* Off by default, i.e. no guarantees that {@code AopContext} access will work.
* @since 4.3.1
*/
boolean exposeProxy() default false; }
这个AspectJAutoProxyRegistrar在刷新容器的时候BeanPostProcessor后置处理器,在bean创建后执行这个后置处理器看是否需要AOP代理
class AspectJAutoProxyRegistrar implements ImportBeanDefinitionRegistrar { /**
* Register, escalate, and configure the AspectJ auto proxy creator based on the value
* of the @{@link EnableAspectJAutoProxy#proxyTargetClass()} attribute on the importing
* {@code @Configuration} class.
*/
@Override
public void registerBeanDefinitions(
AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { AopConfigUtils.registerAspectJAnnotationAutoProxyCreatorIfNecessary(registry); AnnotationAttributes enableAspectJAutoProxy =
AnnotationConfigUtils.attributesFor(importingClassMetadata, EnableAspectJAutoProxy.class);
if (enableAspectJAutoProxy != null) {
if (enableAspectJAutoProxy.getBoolean("proxyTargetClass")) {
AopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry);
}
if (enableAspectJAutoProxy.getBoolean("exposeProxy")) {
AopConfigUtils.forceAutoProxyCreatorToExposeProxy(registry);
}
}
} }
继承跟踪到AopConfigUtils#registerAspectJAnnotationAutoProxyCreatorIfNecessary
@Nullable
public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry,
@Nullable Object source) { return registerOrEscalateApcAsRequired(AnnotationAwareAspectJAutoProxyCreator.class, registry, source);
}
springAOP分析的更多相关文章
- SpringAOP使用及源码分析(SpringBoot下)
一.SpringAOP应用 先搭建一个SpringBoot项目 <?xml version="1.0" encoding="UTF-8"?> < ...
- springAop:Aop(Xml)配置,Aop注解配置,spring_Aop综合案例,Aop底层原理分析
知识点梳理 课堂讲义 0)回顾Spring体系结构 Spring的两个核心:IoC和AOP 1)AOP简介 1.1)OOP开发思路 OOP规定程序开发以类为模型,一切围绕对象进行,OOP中完成某个任务 ...
- SpringAOP源码分析总结
1.Advisor(增强器):充当Advice和Pointcut的适配器,类似使用Aspect的@Aspect注解的类(前一章节所述).一般有advice和pointcut属性. 祖先接口为org.s ...
- Spring-AOP源码分析随手记(二)
这次来分析下切面的执行过程. 1.怎么看? 怎么开始看源码呢?就直接从被增强的方法调用那里打断点,看看怎么执行的: 然后就来到了这: 2.初步分析 里面有段: if (this.advised.exp ...
- Spring-AOP源码分析随手记(一)
1.@EnableAspectJAutoProxy(proxyTargetClass = true) 就是弄了个"org.springframework.aop.config.interna ...
- 1.springAOP原理分析
环境:jdk1.8 + spring boot 2.0.9.RELEASE Spring AOP的实现本质上就是代理Proxy + 一系列的拦截器 使用@Aspect,引入依赖 <depende ...
- SpringAOP原理分析
目录 Spring核心知识 SpringAOP原理 AOP编程技术 什么是AOP编程 AOP底层实现原理 AOP编程使用 Spring核心知识 Spring是一个开源框架,Spring是于2003年兴 ...
- 基于个人理解的springAOP部分源码分析,内含较多源码,慎入
本文源码较多,讲述一些个人对spring中AOP编程的一个源码分析理解,只代表个人理解,希望能和大家进行交流,有什么错误也渴求指点!!!接下来进入正题 AOP的实现,我认为简单的说就是利用代理模式,对 ...
- 关于struts2的过滤器和mybatis的插件的分析
网上一搜,发现一篇写的非常棒的博文,就直接复制过来了,供以后复习使用. 前辈博文链接:共三篇: http://jimgreat.iteye.com/blog/1616671: http://jimgr ...
随机推荐
- fiddler笔记:Find Session窗口
通过Edit菜单选项或CTRL+F打开Find Session窗口.其主要是用来搜索捕捉到的请求和响应. find 指定要搜索的文本 Options Search 支持的搜索选项:Requests a ...
- CSS实现单选按钮
import React from 'react' import PropTypes from 'prop-types' import CX from 'classnames' import _ fr ...
- 教你如何进行移动端APP测试
1.安全测试(权限) 1)软件权限:其中包括发送信息,拨打电话,链接网络,访问手机信息,联系人信息等等 2)数据在本地的存储.传输等 3)执行某些操作时导致的输入有效性验证.授权.数据加密等方面 4) ...
- RPC、RMI、REST的区别
初入职场,接触了不少企业常用的技术,与学校实训使用的技术有很大差异,在这里记录一下RPC.RMI与REST的区别. 概念 RPC(Remote Procedure Call,远程过程调用) 一种通过从 ...
- 分布式全局ID的几种生成方案
前言 在互联网的业务系统中,涉及到各种各样的ID,如在支付系统中就会有支付ID.退款ID等. 那一般生成ID都有哪些解决方案呢?特别是在复杂的分布式系统业务场景中,我们应该采用哪种适合自己的解决方案是 ...
- Python与C/C++相互调用(转)
原文链接 作者 一.问题 Python模块和C/C++的动态库间相互调用在实际的应用中会有所涉及,在此作一总结. 二.Python调用C/C++ 1.Python调用C动态链接库 Python调用C库 ...
- 运行tomcat7w.exe提示指定的服务未安装 解决办法
一.问题重现点击bin下tomcat7w.exe出现如下提示:提示指定的服务未安装 二.原因分析tomcat7.exe和tomcat7w.exe要起作用必须先为这两个文件安装服务.其中tomcat7. ...
- pycharm中代码窗口如何分成左右或者上下双栏
操作步骤如下: 其中window->edit_tabs->Split Vertically 是分成左右双栏:选择Split Horizontally 是分成上下双栏
- python并发编程之线程(二):死锁和递归锁&信号量&定时器&线程queue&事件evevt
一 死锁现象与递归锁 进程也有死锁与递归锁,在进程那里忘记说了,放到这里一切说了额 所谓死锁: 是指两个或两个以上的进程或线程在执行过程中,因争夺资源而造成的一种互相等待的现象,若无外力作用,它们都将 ...
- 前端基础(一):HTML内容
HTML介绍 Web服务本质 import socket sk = socket.socket() sk.bind(("127.0.0.1", 8080)) sk.listen(5 ...