Aop spring 切面编程

Aop spring 切面编程

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd

">

<bean id="aspectBean" class="com.xwr.app.cczg.aop.TestAspect" />

<aop:aspectj-autoproxy proxy-target-class="true" /><!--启动aspetj框架 -->

<!--<aop:aspectj-autoproxy />启动aspetj框架 -->

<aop:config>

<aop:aspect id="TestAspects" ref="aspectBean">

<!--配置com.spring.service包下所有类或接口的所有方法 -->

<aop:pointcut id="ljw"

expression="execution(* com.xwr.app.*.*(..))" />

<aop:before pointcut-ref="ljw" method="doBefore" />

<aop:after pointcut-ref="ljw" method="doAfter" />

<aop:around pointcut-ref="ljw" method="doAround" />

<aop:after-throwing pointcut-ref="ljw" method="doThrowing"

throwing="ex" />

</aop:aspect>

</aop:config>

</beans>




public class TestAspect { 

 

    public void doAfter(JoinPoint jp) { 

        System.out.println(&quot;加载之前方法log Ending method: &quot; 

                + jp.getTarget().getClass().getName() + &quot;.&quot; 

                + jp.getSignature().getName()); 

    } 

 

    public Object doAround(ProceedingJoinPoint pjp) throws Throwable { 

        long time = System.currentTimeMillis(); 

        Object retVal = pjp.proceed(); 

        time = System.currentTimeMillis() - time; 

        System.out.println(&quot;运行时间process time: &quot; + time + &quot; ms&quot;); 

        return retVal; 

    } 

 

    public void doBefore(JoinPoint jp) { 

        System.out.println(&quot;加载之后log Begining method: &quot; 

                + jp.getTarget().getClass().getName() + &quot;.&quot; 

                + jp.getSignature().getName()); 

    } 

 

    public void doThrowing(JoinPoint jp, Throwable ex) { 

        System.out.println(&quot;异常处理method &quot; + jp.getTarget().getClass().getName() 

                + &quot;.&quot; + jp.getSignature().getName() + &quot; throw exception&quot;); 

        System.out.println(ex.getMessage()); 

    } 

 

    private void sendEx(String ex) { 

        //TODO 发送短信或邮件提醒 

    } 

}  

为什么切不进来呢??????????????????????




 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值