Spring AOP笔记

SpringAOP

1.加入jar包

com.springsource.org.aopalliance-1.0.0.jar

com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar

spring-aop-4.0.0.RELEASE.jar

spring-aspects-4.0.0.RELEASE.jar

 

commons-logging-1.1.1.jar

spring-beans-4.0.0.RELEASE.jar

spring-context-4.0.0.RELEASE.jar

spring-core-4.0.0.RELEASE.jar

spring-expression-4.0.0.RELEASE.jar

 

2.在配置文件中加入aop命名空间

3.基于注解的方式

 a.在配置文件中加入如下配置

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

 b.把横切关注点的代码抽象到切面的类中

   1>切面首先是一个IOC中的bean,加入@Component注解

   2>切面还需要加入@Aspect注解

 c.在类中声明各种通知

   1>声明一个方法,在方法加入@before注解

  

 d.可以在通知方法中声明一个类型为JoinPoint的参数.然后就能访问链接细节。如方法名称和参数值

@Before("execution(public int com.t.spring.aop.impl.ArithmeticCalculatorImpl.*(int,int))")
	public void beforeMethod(JoinPoint joinPoint){
		
		String methodName=joinPoint.getSignature().getName();
		List<Object> list=Arrays.asList(joinPoint.getArgs());
		
		System.out.println("the method:"+methodName+",args:"+list+" begins");
	}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值