Hello,
I've tried to upgrade a Spring 2.0.0 project to Spring 2.0.1. One problem occured with some of my ProxyFactoryBeans which should be intercepted by one of my AspectJPointcutExpressions.
My Aspect intercepts a method of a proxied interface on the target bean of the ProxyFactoryBean.
I've created the following code for reproducing the problem.
Base Interface:
Proxied Interface:Code:public interface MyService { public void someServiceMethod(); public void someOtherServiceMethod(); public String getMethodCalledMessage(); public void setMethodCalledMessage(String method); }
Implementation (Target Bean):Code:public interface MyServiceToIntroduce extends MyService { public void introducedMethod(); }
Aspect:Code:public class MyServiceImpl implements MyService { private static final Logger logger = Logger.getLogger(MyServiceImpl.class); private String methodCalledMessage; public void someOtherServiceMethod() { logger.info("in someOtherServiceMethod"); this.setMethodCalledMessage("someOtherServiceMethod"); } public void someServiceMethod() { logger.info("in someServiceMethod"); this.setMethodCalledMessage("someServiceMethod"); } public String getMethodCalledMessage() { return this.methodCalledMessage; } public void setMethodCalledMessage(String method) { this.methodCalledMessage = method; } }
applicationContext-proxyFactoryBean.xml:Code:@Aspect public class MyServiceAspect { final Logger logger = Logger.getLogger(MyServiceAspect.class); @Around(value = "execution(* some.package.MyService*.introduced*(..))" + " && target(service)", argNames = "joinPoint, service") public void doIntroduce(ProceedingJoinPoint joinPoint, MyService service) { logger.info("in aspect: doIntroduce"); service.setMethodCalledMessage(joinPoint.getSignature().getName()); } }
Test:Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> <aop:aspectj-autoproxy /> <bean id="myServiceAspect" class="some.package.MyServiceAspect" /> <bean id="myService" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="proxyInterfaces"> <value> some.package.MyServiceToIntroduce </value> </property> <property name="target" ref="myServiceTarget" /> </bean> <bean id="myServiceTarget" class="some.package.MyServiceImpl" /> </beans>
Stacktrace:Code:public class AtAspectJPointcutExpressionWithProxyFactoryBeanInContextTest extends AbstractSingleSpringContextTests { public void testPointcutExpression() throws Exception { MyServiceToIntroduce serviceToIntroduce = (MyServiceToIntroduce) applicationContext .getBean("myService"); serviceToIntroduce.introducedMethod(); assertEquals("introducedMethod", serviceToIntroduce .getMethodCalledMessage()); } @Override protected String[] getConfigLocations() { return new String[] { "classpath:/applicationContext-proxyFactoryBean.xml" }; } }
With Spring 2.0.0 everything works fine! Thanks for your help in advance!Code:org.springframework.aop.AopInvocationException: AOP configuration seems to be invalid: tried calling method [public abstract void test.at.ccservices.spring.aop.service.MyServiceToIntroduce.introducedMethod()] on target [test.at.ccservices.spring.aop.service.MyServiceImpl@136a43c]; nested exception is java.lang.IllegalArgumentException: object is not an instance of declaring class 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) at java.lang.reflect.Method.invoke(Method.java:585) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:280) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:199) at $Proxy10.introducedMethod(Unknown Source) at test.at.ccservices.spring.aop.annotations.AtAspectJPointcutExpressionWithProxyFactoryBeanInContextTest.testPointcutExpression(AtAspectJPointcutExpressionWithProxyFactoryBeanInContextTest.java:15) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at junit.framework.TestCase.runTest(TestCase.java:164) at junit.framework.TestCase.runBare(TestCase.java:130) at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69) at junit.framework.TestResult$1.protect(TestResult.java:110) at junit.framework.TestResult.runProtected(TestResult.java:128) at junit.framework.TestResult.run(TestResult.java:113) at junit.framework.TestCase.run(TestCase.java:120) at junit.framework.TestSuite.runTest(TestSuite.java:228) at junit.framework.TestSuite.run(TestSuite.java:223) at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35) at org.junit.internal.runners.CompositeRunner.run(CompositeRunner.java:29) at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42) at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34) at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52) at org.junit.internal.runners.CompositeRunner.run(CompositeRunner.java:29) at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42) at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34) at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Best Regards,


Reply With Quote