Aspect出现error Type referred to is not an annotation type

ゝ一纸荒年。 2022-04-08 09:20 846阅读 0赞

使用Aspect记录操作日志时,启动项目报以下异常:

  1. 严重: StandardWrapper.Throwable
  2. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcContentNegotiationManager': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error Type referred to is not an annotation type: log

实现代码:

  1. /**
  2. * 前置通知,用于拦截controller层的操作
  3. *
  4. * @param joinPoint
  5. * @param log
  6. */
  7. @Before("controllerAspect() && @annotation(log)")
  8. public void doBefore(JoinPoint joinPoint, SystemControllerLog sysLog) {
  9. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
  10. .getRequest();
  11. String ip = request.getRemoteAddr();
  12. logger.info("ip:" + ip);
  13. }

原因是@Before里的注解和方法中的参数名不一致,改为一致后启动正常:

  1. /**
  2. * 前置通知,用于拦截controller层的操作
  3. *
  4. * @param joinPoint
  5. * @param log
  6. */
  7. @Before("controllerAspect() && @annotation(sysLog)")
  8. public void doBefore(JoinPoint joinPoint, SystemControllerLog sysLog) {
  9. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
  10. .getRequest();
  11. String ip = request.getRemoteAddr();
  12. logger.info("ip:" + ip);
  13. }

发表评论

表情:
评论列表 (有 0 条评论,846人围观)

还没有评论,来说两句吧...

相关阅读