@AspectJ注解的value属性

@Component
@Scope("prototype")
@Aspect(value="perthis(execution(* com.helius.service.impl.*.*(..)))")
//表明当前类是一个切面类
public class LogUtil {

    /**
     * 用于配置当前方法是一个前置通知
     */
    @Before("execution(* com.helius.service.impl.*.saveUser(..))")
    public void printLog(){
        System.out.println("执行打印日志的功能");
    }
}

默认情况下我们的切面类是单例的,当我们指定@Scope("prototype")为多例时,切面类为多例。

在Spring AOP中,切面类的实例只有一个,比如前面我们一直使用的MyAspect类,假设我们使用的切面类需要具有某种状态,以适用某些特殊情况的使用,比如多线程环境,此时单例的切面类就不符合我们的要求了

语法为

perthis(pointcut-expression)

这种切面 类的用法实际业务没遇到过,只做了解。

猜你喜欢

转载自www.cnblogs.com/heliusKing/p/11845948.html