spring-aop的xml配置

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
    <!-- 目标对象 -->
    <bean id="serImpl" class="com.qfServ.UserImpl"></bean>
    <!-- 通知对象 -->
    <bean id="tranAdvi" class="com.qfAdvice.Transaction"></bean>
    <!-- 通知对象置入目标对象 -->
    <aop:config>
        <!-- 选择切入点 *任意返回值,任意方法 ..代表任意参数 -->
        <!--
            任意返回值,包含下的子包. . 前面任意字符*
 <aop:pointcut expression="execution(* com.qfServ..*UserImpl.*(..))" 
        id="poin"/> -->
        <aop:pointcut expression="execution(public * com.qfServ.UserImpl.*(..))" id="poin"/>
        <!-- 编织面 -->
        <aop:aspect ref="tranAdvi">
            <aop:around method="around" pointcut-ref="poin"/>
            <!-- 环绕 开始 ;有异常不调用 -->
            <aop:before method="startTransaction" pointcut-ref="poin"/>
            <aop:after-returning method="commitTran" pointcut-ref="poin"/>    
            <aop:after method="commitTranExcep" pointcut-ref="poin"/>
            <!-- 异常调用 -->
            <aop:after-throwing method="afterThrow" pointcut-ref="poin"/>        
        </aop:aspect>
    </aop:config>

</beans>
        好像类似于西瓜面上嵌入的西瓜子;面就是层次的统一拦截,实现机制大概是代理(静态和动态),该函数被spring配置后就可以作为拦截方法,;反射机制大概和IOC控制反转的DI依赖注入,依赖容器注入有关。

       注释的方式配置

<aop:aspectj-autoproxy></aop:aspectj-autoproxy>

 

@Aspect
public class Transaction2 {
    //前置通知 返回值。文件夹。函数。参数
//    @Before("execution( * com.qfSer..*Impl.*(..))")//老师说的,但是测试没有成功
//    @Before("execution(public * com.qfServ.UserImpl.*(..))")
    
    @Pointcut("execution(public * com.qfServ.UserImpl.*(..))")
    public void pointcut(){}
    
    @Before("Transaction2.pointcut()")
    public void begin(){
        System.out.println("begin ");
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值