赞
踩
在我的方面类的方法中,我想获取参数的值和参数的名称.
如果我没有得到名称仍然可以,但我需要获取传递的参数的值是否可能?
(ptCut表达式没有问题,该方法被调用我用sysouts检查)
我的Aspect方法是这样的:
public void excpetionHappened(Exception e) {
// Log the exception
// log the name of the method name/signature which caused the exception
// log the value of the input parameters to the method
// wrap and throw new exctn
}
提前致谢.
解决方法:
你可以使用周围的建议.
这使得在处理异常时可以访问参数.
public aspect ExceptionReporterAspect {
/** The name of the used logger. */
public final static String LOGGER_NAME = "AspectJExceptionLogger";
/** Logger used to log messages. */
private static final Log LOGGER = LogFactory.getLog(LOGGER_NAME);
pointcut stringRequestHandler() :
execution (@RequestMapping Object the.package..*(..));
Object around(): objectRequestHandler(){
try {
return proceed();
} catch (Exception ex){
Signature sig = thisJoinPointStaticPart.getSignature();
Object[] args = thisJoinPoint.getArgs();
String location = sig.getDeclaringTypeName() + '.' + sig.getName() + ", args=" + Arrays.toString(args);
LOGGER.warn("(AOP detected) exception within " + location, ex);
throw(ex)
}
}
}
标签:java,exception-handling,spring,spring-aop
来源: https://codeday.me/bug/20190630/1334574.html
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。