Hi all,
Firstly, I hope that this is the correct forum for my question. I am having problems with using Spring AOP when deploying code in OSGi bundles. Here is the explanation (I would try to whittle down my actual code to the smallest size possible):
I have two interfaces called NodeConfig and ValidatorAspect.
As the name suggests, ValidatorAspect implements an advice method and aspects are configured in XML as follows:Code:public interface NodeConfig { void add(); } public interface ValidatorAspect { void validate(JoinPoint joinPoint); }
Now, when both the above interfaces are deployed in the same bundle and when a third bundle calls NodeConfig.add(), aspect works just fine with NodeConfig.add() being properly wrapped by the advice.Code:<aop:config> <aop:aspect ref="validatorAspect"> <aop:before pointcut="execution(* a.b.c.NodeConfig.*(..))" method="validate" /> </aop:aspect> </aop:config>
How ever, when I deploy ValidatorAspect in a separate bundle (because I want to use same aspect from multiple bundles), I get the following error when NodeConfig.add() is called:
I am using Spring framework 3.0.6 and Virgo-tomcat-server 3.0.2 for this test. Can any one suggest what maybe at issue here? It appears that when advice and the object being advised are in separate bundles, Spring AOP is running into some problems.Code:Caused by: org.springframework.aop.AopInvocationException: Mismatch on arguments to advice method [public final void $Proxy212.validate(org.aspectj.lang.JoinPoint) throws java.lang.Exception]; pointcut expression [org.aspectj.weaver.internal.tools.PointcutExpressionImpl@49f0f02d]; nested exception is java.lang.IllegalArgumentException: object is not an instance of declaring class at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:624) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:603) at org.springframework.aop.aspectj.AspectJMethodBeforeAdvice.before(AspectJMethodBeforeAdvice.java:39) ........ Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
I do hope that I have described the problem in sufficient detail but if there are any further questions, please feel free to ask.
Thanks,
Raghu


Reply With Quote