spring aop

1、aop支持注解@Aspect
 xml里面必须配置
<aop:aspectj-autoproxy/>
用法,首先:声明一个切面
@Aspect
public class AspectTest{
    @PointCut("execution(* com.ls.service..*.*(..))")
    public void pointCut(){
    }
    @Before("pointCut()")
    public void before(){
    }
}
   通知参数 JoinPoint getArgs()(返回方法参数)、 getThis()(返回代理对象)、getTarget()(返回目标)、 getSignature()(返回正在被通知的方法相关信息)和 toString()
2、aop支持schema(项目常用的)
用法,首先:声明一个切面
public class AspectTest{
    public void before(LogInfo logInfo){
    }
    public void after(JoinPoint joinPoint,LogInfo logInfo){
    }
}
XML配置:
注入Bean
    <bean id="testAspect" class="com.ls.aop.AspectTest"></bean>
aop设置:
    <aop:config>
声明切点:
        实例1.<aop:pointcut id="point" expression="execution(* com.ls.service..*.*(..))"/>//切所有service包里面的方法
        实例2.<aop:pointcut id="point" expression="execution(* com.ls.service..*.*(..)) and @annotation(logInfo)"/>//切所有service包里面的带自定义注解的方法
声明切面:
        <aop:aspect ref="testAspect">
            <aop:after method="after" pointcut="point"></aop:after>
        </aop:aspect>        
    </aop:config>
当在springMVC使用aop时注意:
<mvc:annotation-driven/>
<content:component-scan base-package="com.ls.service">
放在和aop同一xml里面
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值