【spring】【04】AOP概念

1.AOP 面向切面编程

可以用来添加添加日志、统计接口耗时、事务、HystrixCommand

https://blog.csdn.net/huiyanshizhen21/article/details/109406054
https://blog.csdn.net/huiyanshizhen21/article/details/109100908

2.切面、连接点、通知、顾问

被@Aspect注解的类叫做切面类

@Pointcut声明一个连接点

 @Pointcut("execution(public * com.zhenzhen.demo.*.controller.*.*(..))")
	public void log() {
	}

@Before、@After、@Around、@AfterReturning、@AfterThrowing的方法是一个通知

通知和连接点构成一个顾问
@Before(“log()”)

3.EnableAspectJAutoProxy有两个属性,

proxyTargetClass决定是否强制使用cglib,如果false有接口使用jdk动态代理、没有接口使用cglib
exposeProxy决定是否需要把代理类放到一个ThreadLocal对象中暴漏到当前线程中

@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;

}
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页