方式一:注解接口形式@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来处理

博客介绍了AOP的两种实现方式。方式一是注解接口形式,以注解操作方法或类,适用于设计sdk场景,还提及@annotation使用可参考相关链接;方式二更推荐,是从微信点餐平台学到,直接写死aop范围,用@ControllerAdvice处理Controller异常。
1749

被折叠的 条评论
为什么被折叠?



