spring AOP

使用spring的aop,要么引入aspectj,要么cglib!
 

<bean id="aopshow" class="com.zc.springAop.AopShow"></bean> 

<aop:config proxy-target-class="true">
<aop:pointcut expression="execution(* com.zc.service.*.*(..))" id="mypoint"/>
<aop:advisor advice-ref="aopshow" pointcut-ref="mypoint"/>
</aop:config>     

将 aopshow对象配置到spring容器中.

以下为aop:config:

proxy-target-class 属性值被设置为true,那么基于类的代理将起作用(这时需要cglib库)。如果proxy-target-class属值被设置为false或者这个属性被省略,那么标准的JDK 基于接口的代理将起作用。

pointcut:切入点  

expression="execution(* com.zc.service.*.*(..))"   匹配的是com.zc.service下的所有的类的方法.

aop:advisor: 放置一个通知和一个切入点的切面

advice: 通知 ,(执行代码或方法


以下是使用 aspectj ---面向切面框架: 使用JDK5.0注解.

<aop:aspectj-autoproxy>的作用是自动为spring容器中的那些匹配@aspectj 切面的bean创建代理,完成切面织入.

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

package com.zc.springAop;


import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class AopTwo {
@Pointcut("execution(* com.zc.service.*.*(..))")
public void a(){

}
@Before(value = "a()")
public void showOne(){
System.out.println("今天星期六.");
}
@After(value = "a()")
public void showTwo(){
System.out.println("继续奋斗.");
}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值