测试aop时出现一个bug:
配置完spring配置文件、测试用例之后运行,报错:
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [mycom.test.aop.ArithmeticCalculator] is defined: expected single bean but found 0:
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:271)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1101)
at mycom.test.aop.MainTest.main(MainTest.java:15)
原因分析:
报错信息的字面意思是没有找到ArithmeticCalculator类,开始时我以为是自动扫包配错了(– <context:component-scan base-package="mycom"></context:component-scan> –),后来发现不是,是切面类中类的定位配错了,类的定位写成了类的接口地址;
(– @Before("execution(public int mycom.test.aop.ArithmeticCalculatorImpl.*(int, int))") –)
Spring AOP配置错误解析
本文分析了在Spring AOP测试中遇到的一个典型错误:找不到指定类型的Bean定义。通过逐步排查,从自动扫描配置到切面类的具体实现,最终定位到问题所在并给出了解决方案。
2997

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



