1
此问题可能很简单,但我无法找到解决方案。 我正在使用Spring AOP,目前我只是试图获取对由框架本身创建的代理对象的引用。 我接着this线程提供的说明,但我仍然得到以下异常:线程“main” java.lang.IllegalStateException无法访问Spring AOP中的代理对象
异常:找不到当前代理:设置“exposeProxy”属性上奉劝“真正'来使其可用。
下面是我的springContext.xml所需的条目:
<aop:aspectj-autoproxy expose-proxy="true"/>
这是我的定义方面:
@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!");
}
主法,一切得到测试:
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(...);
Actor actor = (Actor) context.getBean("actor");
actor.play();
}
这是Actor类中引发异常的方法:
public void play() {
AopContext.currentProxy();
System.out.println("Actor starts playing his role...");
}
该方面编织并正确调用。
非常感谢!