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>
总结
- 如果以后看见类型转换异常,先看是什么类型转换异常,然后再从它的配置入手。
相关文章推荐
- Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Cannot cre
- Class org.apache.struts2.json.JSONWriter can not access a member of class org.springframework.aop.TruePointcut with modifiers "public"
- java.lang.ClassCastException: org.springframework.web.servlet.DispatcherServlet cannot be cast to ja
- Spring抛出异常:java.lang.ClassNotFoundException: org.springframework.expression.PropertyAccessor
- ClassCastException: org/springframework/web/servlet/support/JstlUtils$SpringLocalizationContext inco
- org.springframework.aop.framework.AopConfigException: Cannot proxy target class
- 【框架】[Spring]AOP拦截-使用切点:AspectJExpressionPointcut-切点语言
- java.lang.ClassNotFoundException: org.springframework.aop.TargetSource
- java.lang.ClassCastException: org.springframework.web.filter.CharacterEncodingFilter cannot be cast
- Spring 3.0 抛异常 java.lang.ClassNotFoundException: org.springframework.expression.PropertyAccessor
- 报java.lang.ClassCastException: org.springframework.core.io.buffer.DefaultDataBufferFactory cannot be
- Caused by: java.lang.ClassCastException: org.springframework.web.SpringServletContainerInitializer cannot be cast to javax.servlet.ServletContainerInitializer错误解决办法
- Caused by: java.lang.ClassNotFoundException: org.springframework.expression.ExpressionParser
- Caused by: java.lang.ClassCastException: org.springframework.web.SpringServletContainerInitializer c
- A child container failed during start java.lang.ClassCastException: org.springframework.web.SpringSe
- Caused by: java.lang.ClassNotFoundException: org.springframework.expression.ExpressionParser
- org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [c
- java.io.IOException: java.lang.ClassCastException: Cannot cast org.springframework.web.SpringServlet
- Caused by: java.lang.ClassNotFoundException: org.springframework.expression.ExpressionParser
- 在maven项目中使用apache cxf中遇到异常 java.lang.ClassCastException: org.springframework.web.filter.CharacterEncodingFilter cannot be cast to javax.servlet.Filter