spring对AOP的支持03

注:本例中Client.java、UserManager.java、UserManagerImpl.java、applicationContext.xml        4个类的代码和上一篇日志一致


spring对AOP的支持
Aspect默认情况下不用实现接口,但对于目标对象(UserManagerImpl.java),在默认情况下必须实现接口
如果没有实现接口必须引入CGLIB库

我们可以通过Advice中添加一个JoinPoint参数,这个值会由spring自动传入,从JoinPoint中可以取得
参数值、方法名等等


SecutityHandler.java代码如下:
package com.wdh.spring;
import org.aspectj.lang.JoinPoint;

public class SecurityHandler {
public void checkSecurity(JoinPoint joinPoint){
  

//获得参数
  Object[] args = joinPoint.getArgs();
  for(int i=0;i<args.length;i++){
   System.out.println(args);
  }


//获得方法名称
  System.out.println(joinPoint.getSignature().getName());
  
  System.out.println("=========checkSecurity()==========");
}

}


测试结果如下:
2009-05-18 20:50:21,835 INFO [org.springframework.core.CollectionFactory] - JDK 1.4+ collections available
2009-05-18 20:50:21,876 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from class path resource [applicationContext.xml]
2009-05-18 20:50:22,120 INFO [org.springframework.context.support.ClassPathXmlApplicationContext] - Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=31476927]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [org.springframework.aop.config.internalAutoProxyCreator,securityhandler,usermanager,allAddMethod,org.springframework.aop.aspectj.AspectJPointcutAdvisor]; root of BeanFactory hierarchy
2009-05-18 20:50:22,132 INFO [org.springframework.context.support.ClassPathXmlApplicationContext] - 5 beans defined in application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=31476927]
2009-05-18 20:50:22,142 INFO [org.springframework.aop.framework.DefaultAopProxyFactory] - CGLIB2 not available: proxyTargetClass feature disabled
2009-05-18 20:50:22,202 INFO [org.springframework.context.support.ClassPathXmlApplicationContext] - Bean 'org.springframework.aop.config.internalAutoProxyCreator' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2009-05-18 20:50:22,203 INFO [org.springframework.context.support.ClassPathXmlApplicationContext] - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@9b42e6]
2009-05-18 20:50:22,206 INFO [org.springframework.context.support.ClassPathXmlApplicationContext] - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@17431b9]
2009-05-18 20:50:22,207 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [org.springframework.aop.config.internalAutoProxyCreator,securityhandler,usermanager,allAddMethod,org.springframework.aop.aspectj.AspectJPointcutAdvisor]; root of BeanFactory hierarchy]
Jack
123
addUser
=========checkSecurity()==========
-------UserManagerImpl.addUser()----------
-------UserManagerImpl.deleteUser()----------

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值