我已经编写了一个AOP方面,它将拦截我的全局异常处理程序,但它会产生意外行为,因为进行连接点为空,当我尝试从中获取参数时它会导致<?php
if(isset($_POST['exchange_submit'])) {
$exchange = $_POST['productName'];
foreach($exchange as $product_name) {
echo $product_name;
}
}
?>
。
NullPointerException
我的全局异常处理程序:
@Around("execution(* common.controller.GlobalExceptionHandler.handleException(..))")
public Object performTransactionIdCollectingFromGlobalExceptionHandler(ProceedingJoinPoint pjp) throws Throwable {
Object[] arguments = pjp.getArgs();
for (int i = 0; i < arguments.length; i++)
{
if (KioskProcessorException.class.isAssignableFrom(arguments[i].getClass()))
{
Long trId = ((KioskProcessorException) arguments[i]).getTransactionId();
if(trId != null) {
String transactionId = trId.toString();
ThreadContext.put("trId", transactionId);
}
}
}
Object returnObj = pjp.proceed();
ThreadContext.clearMap();
return returnObj;
}
}
问题是当调用全局异常处理程序时,它返回一个错误,表示pjp为null:
@ControllerAdvice(basePackages = "base")
public class GlobalExceptionHandler
{
@Autowired
private IErrorMappingService service;
@ExceptionHandler(Exception.class)
@ResponseBody
public BaseControllerResponseEntity handleException(HttpServletRequest request, HttpServletResponse response,
Exception ex)
{
//handle exception here
}