Spring之aop(关键性概念,前置,后置,环绕,异常,过滤通知的用法及作用)

import java.lang.reflect.Method;

import java.util.Arrays;

import org.springframework.aop.MethodBeforeAdvice;

public class MyMethodBeforeAdvice implements MethodBeforeAdvice{

/**

* 前置通知(验证)

* @param method

* @param arg1

* @param target

* @throws Throwable

*/

public void before(Method method, Object[] arg1, Object target) throws Throwable {

String clzName = target.getClass().getName();

String MethodName = method.getName();

String params = Arrays.toString(arg1);

System.out.println(“买书评论前加系统日志:”+clzName+“.”+MethodName+“(”+params+“)”);

}

}

target:目标对象

method:被触发的目标对象的方法

arg1:目标对象的目标方法携带的参数

4,配置

在spring-context.xml中,配置目标

获取bookBiz,运行输出

IBookBiz iBookBiz = (IBookBiz) applicationContext.getBean(“bookBiz”);

运行只是输出,但是没有验证

因此我们需要调用MyMethodBeforeAdvice里面的方法

首先我们要在spring-context.xml中,配置前置通知

再配置 ,生成代理对象 (目标+通知)

<bean class=“org.springframework.aop.framework.ProxyFactoryBean”

id=“proxyFactoryBean”>

  • 16
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值