Aspect出现error Type referred to is not an annotation type
使用Aspect记录操作日志时,启动项目报以下异常:
严重: StandardWrapper.Throwable
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
实现代码:
/**
* 前置通知,用于拦截controller层的操作
*
* @param joinPoint
* @param log
*/
@Before("controllerAspect() && @annotation(log)")
public void doBefore(JoinPoint joinPoint, SystemControllerLog sysLog) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
.getRequest();
String ip = request.getRemoteAddr();
logger.info("ip:" + ip);
}
原因是@Before里的注解和方法中的参数名不一致,改为一致后启动正常:
/**
* 前置通知,用于拦截controller层的操作
*
* @param joinPoint
* @param log
*/
@Before("controllerAspect() && @annotation(sysLog)")
public void doBefore(JoinPoint joinPoint, SystemControllerLog sysLog) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
.getRequest();
String ip = request.getRemoteAddr();
logger.info("ip:" + ip);
}
还没有评论,来说两句吧...