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

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用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);
	}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值