支持高度灵活的扩展与切面能力
Spring 可以基于注解做 AOP、权限校验、日志、监控等统一增强。
通过注解就能给方法附加通用能力,不用侵入业务代码,实现无侵入增强。
使用注解实现 AOP
| @Aspect
@Component
public class LogAspect {
@Around("@annotation(com.example.annotation.Log)")
public Object logMethod(ProceedingJoinPoint joinPoint) throws Throwable {
// 日志记录逻辑
return joinPoint.proceed();
}
}
@Log // 只需添加此注解,方法就会被自动增强
public void businessMethod() {
// 业务逻辑
}
|