AOP快速入门
1.导入AOP相关坐标(Spring-contex和aspect jweaver)
2.创建目标接口和目标类(内部有切点)
3.创建切面类(内部有增强方法)
4.将目标类和切面类的对象创建权交给spring
5在applicationContextxml中配置织入关系
<!--目标对象-->
<bean id = "xx" class = "被增强目标对象的全限定名"></bean>
<!--切入对象-->
<bean id = "xx" class = "增强方法的全限定名"></bean>
<!--配置织入:告诉spring框架 那些方法(切点)需要那些增强(前置、后置....)-->
<aop:config>
<!--声明切面-->
<aop:aspect ref = "增强方法的全限定名的id">
<!--切面:切点+通知-->
<aop:before(/其他) method = "增强方法的方法名" pointcut = "execution([修饰符]返回值类型。类名。方法名(参数))">
</aop:aspect>
</aop:config>
6.测试代码(用到junit)
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicatinContext.xml")
public class AopTest{
@Autowired
private 被增强的目标方法的接口名 xx;
@Test
public void test(){
xx.被增强的目标方法的方法名();
}
}