This issue might be kind of simple but I just can't find the solution. I'm using Spring AOP and currently I'm only trying to acquire a reference to a proxy object created by the framework itself. I followed the instructions provided by this thread, but I'm still getting the following exception:
Exception in thread "main" java.lang.IllegalStateException: Cannot find current proxy: Set 'exposeProxy' property on Advised to 'true' to make it available.
Here's the required entry in my springContext.xml:
<aop:aspectj-autoproxy expose-proxy="true"/>
This is my aspect definition:
@Aspect
public class DynamicAspect {
@Pointcut("execution(* addition.aop.Actor.play(..))")
public void play() {
}
@Before("play()")
public void directorGivesInstructions() {
System.out.println("Director: Light, camera, action!");
}
The main-method where everything gets tested:
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(...);
Actor actor = (Actor) context.getBean("actor");
actor.play();
}
This is the method in the Actor class that raises the exception:
public void play() {
AopContext.currentProxy();
System.out.println("Actor starts playing his role...");
}
The aspect is weaved in and called properly.
Thank you very much!