使用自定义注解+Spring切面 异常 error at ::0 formal unbound in pointcut

错误代码:	
@Before("within(com.mumu.global..*) && @annotation(LoggerAdd)")//@annotation里添加的是方法中的对象
	public void addBeforeLogger(JoinPoint joinPoint, LoggerAdd logger) {
		logger.info(date.format(System.currentTimeMillis()) + "调用[" + loggerAdd.logDescription() + "]开始");
		//logger.info(joinPoint.getSignature().toString());

		logger.info("调用方法:{},请求参数:{}", joinPoint.getSignature(), parseParames(joinPoint.getArgs()));

	}
在LoggerAdvice类中,使用了@annotation, 一直报错.研究半天,才发现@annotation里的内容对应的是
addBeforeLogger方法里的对象名,而不是自定义的注解类名
正确代码如下
@Before("within(com.mumu.global..*) && @annotation(logger)")//@annotation里添加的是方法中的对象,而不是方法里的类
	public void addBeforeLogger(JoinPoint joinPoint, LoggerAdd logger) {
		logger.info(date.format(System.currentTimeMillis()) + "调用[" + loggerAdd.logDescription() + "]开始");
		//logger.info(joinPoint.getSignature().toString());

		logger.info("调用方法:{},请求参数:{}", joinPoint.getSignature(), parseParames(joinPoint.getArgs()));

	}

aop自动日志参考

https://blog.csdn.net/itguangit/article/details/78757782

猜你喜欢

转载自blog.csdn.net/hjl21/article/details/80924809