我有以下方法:
public ClassifyCamel(Camel camel) {
if (camel.isHavingSingleHump()) {
return SINGLE_HUMP_CAMEL;
}
}
是否可以创建一个替换整个方法逻辑的方面?例如:
@Aspect
.
.
@Before("ClassifyCamel") {
if (camel.isRich) {
return RICH_CAMEL;
}
}
最佳。
答案 0 :(得分:3)
您可以使用 @Around 建议,以便在方法执行之前和之后执行一些日志。
您可以在此查看示例:
@Aspect
public class LoggingAspect {
@Around("execution(* com.yourPackage.YourClass.yourMethod(..))")
public void logAround(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("Around before is running!");
/*
* IF YOU DON'T DO THIS YOU CAN SKIP YOUR METHOD EXECUTION.
* You can do whatever you need
*/
joinPoint.proceed(); //execute the method.
System.out.println("Around after is running!");
}
}
希望能提供帮助