您的位置:首页 > 编程语言 > ASP

ClassCastException: org.springframework.aop.aspectj.AspectJExpressionPointcut

2020-07-28 15:32 1511 查看

问题

Exception in thread "main" java.lang.ClassCastException: org.springframework.aop.aspectj.AspectJExpressionPointcut cannot be cast to com.wei.service.IAccountService
at AOPTest.main(AOPTest.java:9)

原因

  • 将切点表达式的id与AccountService的实现类的bean的id取了一样的名字。
<bean id="accountService" class="com.wei.service.impl.AccountServiceImpl" ></bean>
<aop:config >
<aop:pointcut id="accountService" expression="execution(* com.wei.service.*.*(..))"/>
<aop:aspect id="logAdvice" ref="logger">
<!--配置通知的类型,并且建立通知的方法和切入点方法的关联。-->
<aop:before method="printLog" pointcut-ref="accountService" />
</aop:aspect>
</aop:config>

解决

  • 修改id即可。
<bean id="accountService" class="com.wei.service.impl.AccountServiceImpl" ></bean>
<aop:config >
<aop:pointcut id="servicePointCut" expression="execution(* com.wei.service.*.*(..))"/>
<aop:aspect id="logAdvice" ref="logger">
<!--配置通知的类型,并且建立通知的方法和切入点方法的关联。-->
<aop:before method="printLog" pointcut-ref="servicePointCut" />
</aop:aspect>
</aop:config>

总结

  • 如果以后看见类型转换异常,先看是什么类型转换异常,然后再从它的配置入手。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐