方式一:注解接口形式@interface
以注解形式对方法或者类进行操作(志远的方法),该方法更倾向于在设计sdk场景中应用,以Around为例:
接口@AroundInterface
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface AroundInterface {
String methodName() default "";
}
切面类AroundAspect
关于@annotation的使用,详见AspectJ切入点详解:
https://www.jianshu.com/p/0b78f1156642
连接点
@Component("LoginService")
public class AroundService {
@AroundInterface(methodName = "login")
public void login(String username)
{
System.out.println("user[" + username + "] login");
}
}
方式二(更推荐这种)
从微信点餐平台中学得,该方法是直接写死aop的范围:
Controller抛出的异常可以使用@ControllerAdvice来处理