码迷,mamicode.com
首页 > 其他好文 > 详细

使用Adivisor配置增强处理

时间:2015-10-30 12:32:09      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

使用Adivisor配置增强处理

  实现步骤:

    1、通过MethodBeforeAdivice接口实现前置增强处理

 1 public class ServiceBeforeAdvisor implements MethodBeforeAdvice {
 2     private Logger logger = Logger.getLogger(ServiceBeforeAdvisor.class);
 3     @Override
 4     public void before(Method method, Object[] args, Object target)
 5             throws Throwable {
 6         logger.info("启动事务");
 7         logger.info("连接点对象:"+target.getClass().getSimpleName());
 8         logger.info("连接点方法:"+method.getName());
 9         logger.info("连接点方法参数:"+args[0]);
10         
11     }
12     
13 }

    2、使用<aop:advisor>标签织入增强处理

 

1 //注意:advisor要放在aspect前面
2     <bean id="userService" class="com.pb.service.UserService"></bean>
3      <bean id="serviceBeforeAdvisor" class="com.pb.aop.ServiceBeforeAdvisor"></bean>
4      <aop:config>
5          <aop:pointcut expression="execution(public * com.pb.service.*.*(..))" 
                id="servicePointcut"/> 6 <aop:advisor advice-ref="serviceBeforeAdvisor" pointcut-ref="servicePointcut"/> 7 </aop:config>

测试类

1 public class Test {
2     public static void main(String[] args) {
3         ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext
                    ("applicationContext.xml"); 4 UserService service = (UserService)context.getBean("userService"); 5 service.addUser(new User()); 6 } 7 }

 

使用Adivisor配置增强处理

标签:

原文地址:http://www.cnblogs.com/xuerong/p/4922715.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!