使用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);
}
本文介绍了一种在使用Aspect记录操作日志时遇到的启动异常问题,并提供了详细的解决方案。问题出现在@Before注解与方法参数名称不匹配导致的错误,通过调整参数名称使其与注解一致后,成功解决了启动异常。
3777

被折叠的 条评论
为什么被折叠?



