spring AOP使用xml配置时出现切面及通知时出现error at ::0 formal unbound in pointcut

本文详细解析了在Spring框架中配置AOP(面向切面编程)时的常见错误,重点介绍了如何正确配置切面的通知方法,尤其是返回通知和异常通知,以及如何使用JoinPoint参数。

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

看到https://www.cnblogs.com/15ho/p/5964279.html这篇博客才发现我的错误

在配置时

		<!-- 配置切面及通知 -->
		<aop:aspect ref="loggingAspect" order="2">
			<aop:before method="beforeMethod" pointcut-ref="pointcut"/>
			<aop:after method="afterMethod" pointcut-ref="pointcut"/>
			<aop:after-throwing method="afterThrowingMethod" pointcut-ref="pointcut"/>
			<aop:after-returning method="afterReturningMethod" pointcut-ref="pointcut"/>
		</aop:aspect>
		<aop:aspect ref="vlidationAspect" order="1">
			<aop:before method="ValidateArgs" pointcut-ref="pointcut"/>
		</aop:aspect>

对应的LoggingAspect类中关于返回通知和异常通知都是有两个参数的,包括一个JoinPoint

	public void afterReturningMethod(JoinPoint joinPoint,Object result) {
		String methodName=joinPoint.getSignature().getName();
		System.out.println("method ends "+methodName+" ends with "+result);
		
	}
	
	
	public void afterThrowingMethod(JoinPoint joinPoint,Object ex) {
		String methodName=joinPoint.getSignature().getName();
		System.out.println("method ends "+methodName+" occurs exception "+ex);
	}

所以在配置的时候应该将除了JoinPoint参数外的参数都添加到配置中,变量名必须保持一致

<aop:after-throwing method="afterThrowingMethod" pointcut-ref="pointcut" throwing="ex"/>
<aop:after-returning method="afterReturningMethod" pointcut-ref="pointcut" returning="result"/>

刚学spring,关于JoinPoint这个参数为什么不用写,还不知道。等大体学完在回顾这些细节

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值