我有一个 @Aspect 和 @Pointcut 方法注释为触发 @Before 一个 @Controller 请求方法,它似乎是匹配的(因为我没有收到任何错误)但它根本没有触发我的建议方法。为了测试目的,我将切入点更改为尽可能具体,并且在应用程序启动期间没有遇到任何绑定错误。
这是我的控制器方法(类是com.xyzMyController):
@RequestMapping(method = RequestMethod.POST, produces = "application/json", consumes = "application/json")
@ResponseBody
public SubmissionResponse submitMethod(@Valid @RequestBody final SubmissionRequest request, HttpServletRequest httpRequest, BindingResult result)
{
if (result.hasErrors()) { throw new BadRequestException(result); }
// ... do stuff ...
}
这是 Aspect 类:
@Aspect
@Component
public class RequestValidatingAspect
{
private static final Logger LOGGER = Logger.getLogger(RequestValidatingAspect.class);
@Inject
private ClientService clientService;
@Inject
private AccountService accountService;
@Pointcut("execution(* com.x.y.z.MyController.submitMethod(*.SubmissionRequest,*.HttpServletRequest,*.BindingResult)) && args(request, httpRequest, result)")
private void requestValidation(SubmissionRequest request, HttpServletRequest httpRequest, BindingResult result) {}
@Before("requestValidation(request,httpRequest,result)")
public void theAdvice(SubmissionRequest request, HttpServletRequest httpRequest, BindingResult result) throws Throwable
{
System.out.println("Before - The Advice");
LOGGER.info("Entering The Advice!");
if(result.hasErrors()){ throw new BadRequestException(result); }
// ... do stuff ...
LOGGER.info("Exiting - The Advice!");
return;
}
}