spring与junit整合测试和spring中的aop

spring与junit整合测试

第一步导包 

导包4+2+aop+test

 第二步配置注解:

建立一个demo02

然后

 接着

 spring中的aop

aop思想:

把事物代码抽取出来 谁需要给谁配

spring中的aop概念:

 aop名词学习

 可以被事物管理的地方就叫连接点

预备加事物管理的方法就叫切入点

给方法配置的管理内容 叫增强的代码

最后 搭配好生成的东西 叫代理对象(看不见摸不到)

通知应用是事物内容,切入点是预备要要事物管理的方法,当你把事物内容配置到切入点的时候就叫织入

已经完全配置好的对象 叫代理对象

 spring中的aop演示

1.导包:

2.准备目标对象

 

 

3.准备通知

 4.配置进行织入,将通知织入目标对象中

 先建立关系

然后粘贴

<aop:config>
    <!--配置切入点
        public void com.oracle.service.UserServiceImp.save()
        void com.oracle.service.UserServiceImp.save()
        * com.oracle.service.UserServiceImp.save()
        * com.oracle.service.UserServiceImp.*()
        
        * com.oracle.service.*ServiceImp.*(..)
                
      -->
      <aop:pointcut expression="execution(* com.oracle.service.*ServiceImp.*(..))" id="pc"/>
      <aop:aspect ref="myAdvice">
              <!--指定名为before的方法作为前置通知  -->
              <aop:before method="before" pointcut-ref="pc"/>
              <!--后置  -->
              <aop:after-returning method="afterReturning" pointcut-ref="pc"/>
              <!--环绕通知  -->
              <aop:around method="around" pointcut-ref="pc"/>
              <!--异常拦截通知  -->
              <aop:after-throwing method="afterException" pointcut-ref="pc"/>
              <!--后置  -->
              <aop:after method="after" pointcut-ref="pc"/>          
      </aop:aspect>
</aop:config>

method里面的方法名必须和

 一样才行

猜你喜欢

转载自www.cnblogs.com/www1842564021/p/12655821.html
今日推荐