Java AspectJ\Spring AOP-替换整个方法
我有以下方法:Java AspectJ\Spring AOP-替换整个方法,java,spring,aop,aspectj,Java,Spring,Aop,Aspectj,我有以下方法: public ClassifyCamel(Camel camel) { if (camel.isHavingSingleHump()) { return SINGLE_HUMP_CAMEL; } } 是否可以创建一个方面来替换整个方法逻辑?例如: @Aspect . . @Before("ClassifyCamel") { if (camel.isRich) { return RICH_CAMEL;
public ClassifyCamel(Camel camel) {
if (camel.isHavingSingleHump()) {
return SINGLE_HUMP_CAMEL;
}
}
是否可以创建一个方面来替换整个方法逻辑?例如:
@Aspect
.
.
@Before("ClassifyCamel") {
if (camel.isRich) {
return RICH_CAMEL;
}
}
最好。您可以使用@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!");
}
}
希望对您有所帮助您可以使用@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!");
}
}
希望对您有所帮助您可以使用@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!");
}
}
希望对您有所帮助您可以使用@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!");
}
}
如果你使用
@Around
你可以选择不调用建议的方法。如果你使用@Around
你可以选择不调用建议的方法。如果你使用@Around
你可以选择不调用建议的方法。如果你使用@Around
你可以选择不调用建议的方法。