Spring 3 AOP java.lang.ClassCastException: $Proxy43 cannot be cast -
i use spring 3.1 , apo(proxy).
annotation provided used pointcat. in case spring aop proxy method "getmergemappingsandcals" annotated calendarmappingannotation
my advise afterreturning
aspect:
@component @aspect public class mappingfilteraspect{ /** * * @param retval */ @afterreturning( pointcut="@annotation(...annotation.calendarmappingannotation)", returning="retval" ) public void calendarmappingfilter(object retval) { } }
annotation:
@retention(retentionpolicy.runtime) @target(elementtype.method) public @interface calendarmappingannotation { }
usage:
@component public class apoimappingmanagerimpl implements apoimappingmanager, applicationcontextaware, serializable { ... @calendarmappingannotation public mergedmapandcalsbeancollection getmergemappingsandcals(){ ... } }
configuration:
<context:component-scan base-package="...aus.aspect" /> <aop:aspectj-autoproxy/>
stacktrace:
java.lang.classcastexception: $proxy43 cannot cast ...mapping.cals.apoimappingmanagerimpl [jvm ...] @ ...helpers.savefillrestcalsclienthelper.init(savefillrestcalsclienthelper.java:62) [jvm ...] @ ...dispatcherimpl.loadplugin(dispatcherimpl.java:426) [jvm ...] @ ...dispatcher.dispatcherimpl.run(dispatcherimpl.java:181) [jvm ...] @ ...dispatcherimpl.complete(dispatcherimpl.java:319) [jvm ...] @ ...dispatcherimpl.process(dispatcherimpl.java:259) [jvm ...] @ ...runnerimpl.run(runnerimpl.java:88) [jvm ...] @ ...jvmlauncherslave.main(jvmlauncherslave.java:40)
the behavior looks correct.
it looks casting instance of bean of type apoimappingmanagerimpl
, code throwing runtime exception. reason expected behavior because underlying using spring aop , spring aop creates dynamic proxy you, proxy implements interface apoimappingmanager
, internally composes apoimappingmanagerimpl
, delegates calls composed class. proxy implements apoimappingmanager
, not extend apoimappingmanagerimpl
, hence error.
to fix should if required casting interface not implementation.
Comments
Post a Comment