转载:http://blog.csdn.net/u011710466/article/details/52888277
在spring的配置中,会用到这两个标签.那么他们的区别是什么呢?
 
    <bean id="testAdvice" class="com.myspring.app.aop.MyAdvice"/> //切面代码
    使用<aop:aspect>配置时,
    如果切面代码是自动注入的bean,那么<aop:aspect>的ref属性直接写bean的注入名字就可以了!
    <aop:config>
        <aop:aspect ref="testAdvice" id="testAspect">
            <aop:pointcut expression="(execution(* com.myspring.app.aop.TestPoint.*(..)))" id="testPointcut"/>
            <aop:before  method="doBefore" pointcut-ref="testPointcut"/>
        </aop:aspect>
    </aop:config>
 
    <aop:config>
        <aop:pointcut expression="(execution(* com.myspring.app.aop.TestPoint.*(..)))"  id="mypoint"/>
        <aop:advisor advice-ref="testAdvice" pointcut-ref="mypoint"/>
    </aop:config>
注意:2种格式的书写次序.
=========================================================================
package com.myspring.app.aop;
 
import java.lang.reflect.Method;
 
import org.aspectj.lang.JoinPoint;
import org.springframework.aop.MethodBeforeAdvice;
 
/**
 * 方法前置通知
 * @author Michael
 *
 */
@Component("myAdvice")//如果是自动装配,在定义切面的时候直接写在ref属性里就可以了
public class MyAdvice implements MethodBeforeAdvice{
    //如果使用aop:advisor配置,那么切面逻辑必须要实现advice接口才行!否则会失败!
    @Override
    public void before(Method method, Object[] args, Object target) throws Throwable {
        System.out.println("前置通知");
    }
 
    //如果是<aop:aspect>配置,编写一般的方法就可以了,然后在切面配置中指定具体的方法名称!
    public void doBefore(JoinPoint point) throws Throwable {
 
    }
}

spring Aop中aop:advisor 与 aop:aspect的区别的更多相关文章

  1. ContextLoaderListener和Spring MVC中的DispatcherServlet加载内容的区别

    一:ContextLoaderListener加载内容 二:DispatcherServlt加载内容 ContextLoaderListener和DispatcherServlet都会在Web容器启动 ...

  2. Spring Boot 中application.yml与bootstrap.yml的区别

    其实yml和properties文件是一样的原理,且一个项目上要么yml或者properties,二选一的存在. 推荐使用yml,更简洁. bootstrap与application1.加载顺序这里主 ...

  3. Spring Boot中application.yml与bootstrap.yml的区别(转载)

    说明:其实yml和properties文件是一样的原理,主要是说明application和bootstrap的加载顺序.且一个项目上要么yml或者properties,二选一的存在. Bootstra ...

  4. Spring Boot中application.yml与bootstrap.yml的区别(转)

    说明:其实yml和properties文件是一样的原理,主要是说明application和bootstrap的加载顺序.且一个项目上要么yml或者properties,二选一的存在. Bootstra ...

  5. ContextLoaderListener和Spring MVC中的DispatcherServlet加载内容的区别【转】

    原文地址:https://blog.csdn.net/py_xin/article/details/52052627 ContextLoaderListener和DispatcherServlet都会 ...

  6. Spring MVC中<mvc:annotation-driven />和<context:annotation-config />的区别分析

    个人最简单的使用理解: <mvc:annotation-driven />是管理静态资源的,比如静态页面,返回JSON这些. <context:annotation-config / ...

  7. Spring Boot 中application.yml与bootstrap.yml的区别(转)

    yml与properties其实yml和properties文件是一样的原理,且一个项目上要么yml或者properties,二选一的存在. 推荐使用yml,更简洁. bootstrap与applic ...

  8. Spring 框架中 ModelAndView、Model、ModelMap 的区别

    Model Model 是一个接口, 其实现类为ExtendedModelMap,继承了ModelMap类. public class ExtendedModelMap extends ModelMa ...

  9. Spring框架中ModelAndView、Model、ModelMap的区别

    转自:http://blog.csdn.net/liujiakunit/article/details/51733211 1. Model Model 是一个接口, 其实现类为ExtendedMode ...

随机推荐

  1. HashMap和HashTable区别

    HashMap和HashTable区别 HashMap--->允许控制/线程安全 HashTable-->线程不安全

  2. c++命名规则

    命名规则根据不同公司有略微不同,这里按照google c++的编程标准1.文件名-全部用小写字母和下划线或横线组成,例如my_useful_class.ccmy-useful-class.ccmyus ...

  3. 夺命雷公狗—angularjs—10—angularjs里面的内置函数

    我们没学一门语言或者框架,几乎里面都有各自的语法和内置函数,当然,强悍的angularjs也不例外,他的方法其实常用的没多少,因为很多都可以用源生jis几乎都能完成一大部分.. <!doctyp ...

  4. Android SDK 安卓失败 提示: “Failed to fetch URL…” 的错误提示

    解决方法: 1.   打开Tools 选择 options  将  第一个复选框勾上.           (尝试一下,如果还是失败,参考2) 2.   打开本地host 文件, 在最后一行添加   ...

  5. zw版_Halcon图像库delphi接口文件

    zw版_Halcon图像库delphi接口文件 Halcon图像库delphi接口文件,根据安装时用户设置的文件目录不同,会有所差异,笔者一般安装在delphi的import目录下.     参见:& ...

  6. zw版【转发·台湾nvp系列Delphi例程】HALCON FillUp2

    zw版[转发·台湾nvp系列Delphi例程]HALCON FillUp2 procedure TForm1.Button1Click(Sender: TObject);var op : HOpera ...

  7. 【crunch bang】文件管理器-thunar

    Thunar拥有的实用功能: 缩略图查看 批量重命名 安装: $ sudo apt-get install thunar 加速thunar启动速度 sudo leafpad /usr/share/gv ...

  8. Qt源码包中的一段代码

    之所以单独拣出来是因为Qt的开发者们给普通开发者提供了高效编程的商业代码例子: bool QWidget::testAttribute_helper(Qt::WidgetAttribute attri ...

  9. javascript 正则表达式(二)

    /* 正则表达式方法:test(),exec(),String对象方法:match(),search(),replace(),split() 1.test()方法: 用法:  regexp对象实例.t ...

  10. URL 中#号,? ,&的作用 (摘抄整理 链接为学习地址)

    1. 一峰的网络日志:http://www.ruanyifeng.com/blog/2011/03/url_hash.html get: 1.页面滚动到指定页面的指定位置 (eg: http://ww ...