Trouble Shooting(1)AOP Configuration

本文介绍了一次Spring AOP配置中遇到的参数错误问题及其解决方案。主要原因是配置文件中声明的方法参数数量与实际数量不符,导致了运行时异常。通过调整配置文件中的参数数量并确保与方法签名一致,成功解决了问题。
Trouble Shooting(1)AOP Configuration
Today, once I configured AOP around to my spring project. It gives me this kind of error message.

Error Message:
java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:254)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:835)

Solution:
Mostly, this is because of the parameters error. I put 3 parameters in my around method. But I only got 2 in the configuration file. That is the root cause. After I changed my configuration, my files are as follow:

<aop:aspect ref="advisor_catalogControllerImpl_search">
<aop:pointcut id="catalogControllerImpl_search" expression="execution(* com.sillycat.graphite.web.controller.impl.CatalogControllerImpl.search(..)) and args(request,response,..)"/>
<aop:before pointcut-ref="catalogControllerImpl_search" method="adviceBefore"/>
<aop:around pointcut-ref="catalogControllerImpl_search" method="adviceAround"/>
<aop:after-returning pointcut-ref="catalogControllerImpl_search" returning="modelAndView" method="adviceAfterReturning"/>
</aop:aspect>

<bean id="advisor_catalogControllerImpl_search" class="com.sillycat.graphite.web.customization.CustomCabelasCatalogController_search"/>

public class CustomCabelasCatalogController_search extends
ControllerAdvisorBase {
…snip…
}

public class ControllerAdvisorBase {

public void runBefore(HttpServletRequest request, HttpServletResponse response) {
// Need to be customized by store
}

public void runAfterReturning(HttpServletRequest request, HttpServletResponse response, ModelAndView modelAndView) {
// Need to be customized by store
}

public Object runAround(ProceedingJoinPoint joinPoint, HttpServletRequest request, HttpServletResponse response) throws Throwable {
// Need to be customized by store
return joinPoint.proceed();
}

public final void adviceBefore(JoinPoint jp, HttpServletRequest request, HttpServletResponse response) {
log("Entering", jp, null);
runBefore(request, response);
}

public final void adviceAfterReturning(JoinPoint jp, HttpServletRequest request, HttpServletResponse response, ModelAndView modelAndView) {
log("Exiting", jp, modelAndView);
runAfterReturning(request, response, modelAndView);
}

public final Object adviceAround(ProceedingJoinPoint jp, HttpServletRequest request, HttpServletResponse response) throws Throwable {
log("Around", jp, null);
return runAround(jp, request, response);
}

private void log(String prefix, JoinPoint jp, ModelAndView modelAndView) {
StringBuilder sb = new StringBuilder();
sb.append(prefix).append(" ").append(jp.toString());

if (logger.isDebugEnabled()) {
Object[] args = jp.getArgs();
if (args != null && args.length != 0) {
sb.append(" with ").append(args.length).append(" args.\n");
for (int i = 0; i < args.length; ++i)
sb.append("args[").append(i).append("]: ").append(args[i]).append("\n");
}

if (modelAndView != null)
sb.append("Returned ").append(modelAndView);

logger.debug(sb.toString());
} else
logger.info(sb.toString());
}
...snip...
}


references:
http://forum.springsource.org/showthread.php?62460-Formal-unbound-in-pointcut
故障排除(Troubleshooting)是一种系统性的方法,旨在识别、诊断和解决系统、设备或应用程序中出现的问题或故障,这些问题可能导致系统无法正常工作、性能下降或其他不良影响。该过程涉及收集信息、分析数据、测试假设,并最终确定并实施解决方案,通常需要技术专业知识和经验,可能涉及多个领域,包括硬件、软件、网络、安全等。通过故障排除,可以及时解决问题,确保系统持续稳定运行[^2]。 在不同场景下,故障排除有不同的重点和方法: - **Linux系统**:解决常见的故障排错,需先了解系统的启动流程。在实际生产环境中,系统和数据基本安装在不同硬盘上,因为数据丢失会给企业带来损失,若系统和数据在同一硬盘,系统崩溃则无法获取数据。遇到故障时,不应首先考虑重装系统[^1]。同时,Linux下快速故障探测会涉及一些概念,如进程的user、PID、%CPU、%MEM、VSZ、RSS、TTY、STAT、START、TIME、COMMAND等信息[^4]。 - **程序员提升能力方面**:程序员可通过多种方式提高故障排除能力,如建立扎实的基础知识,拥有良好的编程基础和对计算机系统、数据结构、算法以及编程语言的深入理解,有助于快速定位问题;学会使用调试工具,熟练掌握各种调试工具,如IDE的调试功能、浏览器的开发者工具、日志分析工具等,可以更高效地找到问题;学习问题解决策略,熟悉常用的问题解决策略,如分治法、逐步细化、自上而下等,能有条不紊地解决问题;保持好奇心和耐心,遇到问题时保持好奇心,善于发现问题的规律,同时耐心分析问题,逐步缩小问题范围;优化代码阅读能力,多阅读别人的代码,有助于理解代码逻辑,从而更容易找到问题所在;学会提问和求助,遇到问题时向同事或网络社区提问,明确问题的关键点,同时从别人的问题和解决方案中汲取经验;复盘总结经验,每次解决问题后进行复盘,总结问题的原因、解决方法和改进方案;模拟故障排除场景,在空闲时间模拟常见的故障排除场景,提高应对问题的能力;深入了解业务,了解业务逻辑和需求,从用户角度看待问题,更容易找到问题所在;持续学习和进步,不断学习新技术、新方法,关注业界动态,参加技术研讨会、线上技术社区等,与其他程序员互动,共同提高[^3]。 - **网络方面**:以突然无法访问某些内部网站为例,可尝试使用`ipconfig /all`、`ipconfig/flushdns`、`ipconfig/release`、`ipconfig/release6 (ip6)`、`ipconfig/renew`、`ipconfig/renew6 (ip6)`等命令,若重启后仍无法解决,发现是DNS Suffix Search List缺失大部分站点,可通过控制面板中的网络连接,右键点击“Ethernet”,选择属性来解决问题[^5]。 ```python # 示例代码:简单的异常处理,模拟故障排除思路 try: num1 = int(input("请输入第一个数字: ")) num2 = int(input("请输入第二个数字: ")) result = num1 / num2 print(f"结果是: {result}") except ValueError: print("输入的不是有效的数字,请输入整数。") except ZeroDivisionError: print("除数不能为零。") ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值