?
Dieses Dokument verwendet PHP-Handbuch für chinesische Websites Freigeben
除了在配置文件中使用<aop:config>或者<aop:aspectj-autoproxy>來(lái)聲明切面。 同樣可以通過(guò)編程方式來(lái)創(chuàng)建代理來(lái)通知目標(biāo)對(duì)象。關(guān)于Spring AOP API的詳細(xì)介紹, 請(qǐng)參看下一章。這里我們重點(diǎn)介紹自動(dòng)創(chuàng)建代理。
類org.springframework.aop.aspectj.annotation.AspectJProxyFactory
可以為一個(gè)或多個(gè)
@AspectJ切面通知的目標(biāo)對(duì)象創(chuàng)建一個(gè)代理。該類的基本用法非常簡(jiǎn)單,示例如下。請(qǐng)參閱Javadoc獲取更詳細(xì)的信息。
// 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();