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...");
}
該方面編織並正確調用。
非常感謝!