I'm having trouble getting a bean from my context and using it now that I'm trying to add in AOP, code is described below, more details about my problem are at the very bottom of this message.
I have defined an aspect using annotations that looks something like this:
In my application context I am defining an instance of "MyDomainObject" and setting up the AOP stuff:Code:@Aspect public class MyAspect { @Before("foo()") public void handleBefore() { System.out.println("handleBefore invoked on MyAspect"); } @Pointcut("execution(* com.acme.foo.MyDomainObject.*(..))") public void foo() {} }
Now my unit test looks like this:Code:... <aop:aspectj-autoproxy> <aop:include name="myAspect"/> </aop:aspectj-autoproxy> <bean id="myAspect" class="com.acme.aspects.MyAspect" /> <bean id="myObject" class="com.acme.foo.MyDomainObject" /> ...
The problem I have is when I get the bean from the context and store it in "tmp", it shows up in the debugger as a JdkDynamicAopProxy, when I try to cast it to a MyDomainObject it fails with a ClassCastException.Code:public class MyAspectTest extends AbstractDependencyInjectionSpringContextTests { /* (non-Javadoc) * @see org.springframework.test.AbstractSingleSpringContextTests#getConfigLocations() */ @Override protected String[] getConfigLocations() { return new String[] {"classpath:/com/acme/test/aspects/aspects-test-config.xml"}; } @Test public void testAspect() { Object tmp = getApplicationContext().getBean("myObject"); MyDomainObject mdo = (MyDomainObject) tmp; mdo.sayHello(); }
Am I missing something??


Reply With Quote