【spring】【04】AOP概念

1.AOP 面向切面编程

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

https://blog.youkuaiyun.com/huiyanshizhen21/article/details/109406054
https://blog.youkuaiyun.com/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;

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值