zoukankan      html  css  js  c++  java
  • spring AOP使用示例

     <aop:aspectj-autoproxy proxy-target-class="true"/>
     <!--CRUDAction代理 通知对象-->
     <bean id="actionPointcut" class="cn.net.comsys.ut.commons.web.aop.ActionPointcut" />
     <!-- CRUDAction切面 -->
     <aop:config>
      <aop:aspect id="CRUDActionProxy" ref="actionPointcut">
       <aop:pointcut id="CRUDActionMethods" expression="execution(public java.lang.String cn.net.comsys.ut.commons.web.action.*Action.*(..))"/>
       <aop:before  pointcut-ref="CRUDActionMethods" method="before"/>
      </aop:aspect>
     </aop:config>



    配置要拦截多个方法可以:

    expression="execution(public java.lang.String cn.net.comsys.ut.commons.web.action.*Action.add(..)) and execution(public java.lang.String cn.net.comsys.ut.commons.web.action.*Action.update(..)) "/
    package cn.net.comsys.ut.commons.web.aop;

    import org.aspectj.lang.JoinPoint;

    import cn.net.comsys.ut.commons.web.action.CRUDAction;
    import cn.net.comsys.ut.log.Log;
    /**
     * 拦截所有请求CRUD的Action
     * @Title: ActionPointcut.java
     * @Package cn.net.comsys.ut.commons.web.aop
     * @Description: TODO
     * Copyright: Copyright (c) 2011 
     * Company:成都康赛电子科大信息技术有限责任公司
     * 
     * 
    @author Comsys-Administrator
     * @date 2012-10-17 下午03:43:49
     * 
    @version V1.0
     
    */
    public class ActionPointcut {

        public void before(JoinPoint pjp){
            Object action =pjp.getTarget();
            if(action instanceof CRUDAction){
                try{
                    CRUDAction crudAction=(CRUDAction) action;
                    crudAction.initAction();
                }catch (Exception e) {
                    Log.error(ActionPointcut.class, "设置action参数错误."+e.getMessage());
                }
            }
        }
    }
  • 相关阅读:
    Web网站架构演变—高并发、大数据
    企业级Nginx Web服务优化实战
    初始化mysql数据库时提示字符编码错误的解决办法
    linux下logrotate 配置和理解
    Centos 5.2下安装多个mysql数据库
    编译安装 mysql 5.5,运行 cmake报错Curses library not found
    Centos 5.5 编译安装mysql 5.5.9
    理解索引的基数
    centos下yum安装mysql5.6后,无法启动 MySQL Daemon failed to start
    如何从MySQL官方Yum仓库安装MySQL5.6
  • 原文地址:https://www.cnblogs.com/jifeng/p/2729362.html
Copyright © 2011-2022 走看看