Spring中AOP的实现就是通过动态代理来实现的。动态代理的实现在上篇blog中已经涉及。Spring中目前最为实用的AOP应用,非用其实现的事务管理机制莫属。也正是这一点,使得Spr
最后,我们还需要定义一个Spring AOP ProxyFactory用于加载执行AOP组件,并且需要将Advice通过IOC的方式注入到接口以及实现类。
对应的配置文件应如下配置从而实现这些内容:
<bean id="myAOPProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>test.aop.spring.DomainObjDAO</value>
</property>
<property name="target">
<ref local="impl" />
</property>
<property name="interceptorNames">
<value>myPointcutAdvisor</value>
</property>
</bean>
<bean id="impl" class="test.aop.spring.DomainObjDAOImpl"/>
万事大吉!写一个TestCase来看一下运行结果:
package test.aop.spring;
import junit.framework.TestCase;