java如何在方法声明中使用@Abround spring aop注释?
如何在方法声明中使用@around spring AOP注释?实际上,java类中有很多重复代码,所以我正在考虑对其进行优化。只有@around执行值每次都会更改,3-4个方法的方法定义是相同的。你能建议我在这种情况下可以做些什么来优化代码吗?在给定的示例中,您可以看到nicdStatus和nicdPortStatus只发生了更改,其余所有的方法定义都是相同的。 请提供一些代码优化建议,因为我的java类中有重复的代码
@Around("execution(* dcp.casa.services.nicd.NicdController.**nicdStatus**(..)) && args(*, relationId,..)")
Object handleRunTest(final ProceedingJoinPoint joinPoint, final String relationId) {
log.info("xyz");
callAbc();
return joinPoint.proceed();
}
@Around("execution(* dcp.casa.services.nicd.NicdController.nicdPortStatus(..)) && args(*, relationId,..)")
Object handleRunTest(final ProceedingJoinPoint joinPoint, final String relationId) {
log.info("xyz");
callAbc();
return joinPoint.proceed();
}
# 1 楼答案
那么,答案很简单:就像重构任何其他Java类一样重构:
如果helper方法也需要访问
String relationId
,只需向其添加另一个参数并相应地调用它