?
本文檔使用 PHP中文網(wǎng)手冊 發(fā)布
除了在配置文件中使用<aop:config>或者<aop:aspectj-autoproxy>來聲明切面。 同樣可以通過編程方式來創(chuàng)建代理來通知目標對象。關于Spring AOP API的詳細介紹, 請參看下一章。這里我們重點介紹自動創(chuàng)建代理。
類org.springframework.aop.aspectj.annotation.AspectJProxyFactory
可以為一個或多個
@AspectJ切面通知的目標對象創(chuàng)建一個代理。該類的基本用法非常簡單,示例如下。請參閱Javadoc獲取更詳細的信息。
// create a factory that can generate a proxy for the given target object AspectJProxyFactory factory = new AspectJProxyFactory(targetObject); // add an aspect, the class must be an @AspectJ aspect // you can call this as many times as you need with different aspects factory.addAspect(SecurityManager.class); // you can also add existing aspect instances, the type of the object supplied must be an @AspectJ aspect factory.addAspect(usageTracker); // now get the proxy object... MyInterfaceType proxy = factory.getProxy();