Spring面向切面编程(AOP)方式二

本文介绍了Spring面向切面编程(AOP)的注解方式,通过创建切面类并减少XML配置来实现更加灵活的编程。切面类无需实现特定接口,直接定义所需的通知。
摘要由CSDN通过智能技术生成

使用注解进行实现:减少xml文件的配置。

1 建立切面类

不需要实现任何特定接口,按照需要自己定义通知。

package org.guangsoft.utils;
import java.util.Date;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
/***
 * 定义用户的切面类
 * ***/
@Component
@Aspect
public class UsersAdvice
{
    // 前置的通知
    @Before("execution(* com.bjsxt.service.impl.*.*(..))")
    public void before()
    {
        System.out.println("before-------------" + new Date());
    }
    // 后置通知
    // @After("execution(* com.bjsxt.service.impl.*.*(..))")
    @AfterReturning(pointcut = "execution(* com.bjsxt.service.impl.*.*(..))", returning = "rv")
    public vo
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值