新建一个AOP类:

public class MyInterceptor2 {
public void doAccessCheck(){
System.out.println("前置通知 ");
}
public void doAfterReturning(){
System.out.println("后置通知 ");
}
public void doAfter(){
System.out.println("最终通知");
}
public void doAround(ProceedingJoinPoint pjp) throws Throwable{
System.out.println("环绕通知前");
pjp.proceed();
System.out.println("环绕通知后");
}
public void doAfterThrowing(Exception e){
System.out.println("例外通知 例外 e:"+e);
}
}

在beans.xml中注入,并配置AOP:

<aop:aspectj-autoproxy />
<bean id="personIService" class="cn.raffaello.service.impl.PersonServiceImpl"/>
<bean id="myInterceptor2" class="cn.raffaello.aop.MyInterceptor2" />
<aop:config>
<!-- 定义切面 -->
<aop:aspect id="aspect" ref="myInterceptor2">
<!-- 定义切入点 -->
<!-- 拦截所有返回值为String的方法:execution(java.lang.String cn.raffaello.service.impl.PersonServiceImpl.*(..)) -->
<!-- 拦截所有返回值非void的方法:execution(!void cn.raffaello.service.impl.PersonServiceImpl.*(..)) -->
<!-- 拦截第一个参数是String的方法:execution(* cn.raffaello.service.impl.PersonServiceImpl.*(java.lang.String,..)) -->
<!-- 拦截包级子包下的所有类的所有的方法:execution(* cn.raffaello.service.*.*(..)) -->
<!-- 拦截参数为String,并且参数名字为name: execution(* cn.raffaello.service.impl.PersonServiceImpl.*(String)) and args(name) -->
<aop:pointcut id="pointcut" expression="execution(* cn.raffaello.service.impl.PersonServiceImpl.*(java.lang.String))" />
<!-- 前置通知 -->
<aop:before pointcut-ref="pointcut" method="doAccessCheck"/>
<!-- 后置通知 -->
<!-- 拦截返回值为String的方法 <aop:after-returning pointcut-ref="pointcut" method="doAfterReturning" returning="retv"/> -->
<aop:after-returning pointcut-ref="pointcut" method="doAfterReturning" />
<!-- 最终通知 -->
<aop:after pointcut-ref="pointcut" method="doAfter" />
<!-- 环绕通知 -->
<aop:around pointcut-ref="pointcut" method="doAround" />
<!-- 例外通知 -->
<aop:after-throwing pointcut-ref="pointcut" method="doAfterThrowing" throwing="e"/>
</aop:aspect>
</aop:config>

Spring、XML配置AOP的更多相关文章

  1. 2015年12月10日 spring初级知识讲解(二)最小化Spring XML配置 注解

    序,随着Spring容器管理Bean数量增加,XML文件会越来越大,而且纯手工配置XML很繁琐,Spring和JAVA都提供了一些注解方式用以简化XML配置. 目录 一.自动装配(autowiring ...

  2. spring xml配置注入改为手动注入过程

    项目中需要使用MQ组件来接受消息,但是有的时候,在使用的时候,并不能满足spring注入的条件,无法注入.例如 在jfinal的config的afterJFinalStart中,由于jfinal集成s ...

  3. springAop:Aop(Xml)配置,Aop注解配置,spring_Aop综合案例,Aop底层原理分析

    知识点梳理 课堂讲义 0)回顾Spring体系结构 Spring的两个核心:IoC和AOP 1)AOP简介 1.1)OOP开发思路 OOP规定程序开发以类为模型,一切围绕对象进行,OOP中完成某个任务 ...

  4. 最小化Spring XML配置

    Spring提供两种技巧,可以帮助我们减少XML的配置数量. 1.自动装配(autowiring)有助于减少甚至消除配置<property>元素和<constructor-arg&g ...

  5. Spring XML配置里的Bean自动装配

    Spring自动装配 这段是我们之前编写的代码,代码中我们使用了P命名空间 并且使用手动装配的方式将car <bean id="address" class="cn ...

  6. Spring 使用xml配置aop

    1.xml文件需要引入aop命名空间 2.xml内容: <?xml version="1.0" encoding="UTF-8"?> <bea ...

  7. Spring XML配置实现AOP

    1:  首先我们要定义 配置成切面的类 package cn.gbx.example; import org.aspectj.lang.ProceedingJoinPoint; import org. ...

  8. Spring基于XML配置AOP

    目录结构: D:\Java\IdeaProjects\JavaProj\SpringHelloWorld\src\cn\edu\bjut\service\StudentService.java pac ...

  9. Spring注解配置Aop

    之前学习了SpringAop的基本原理.http://www.cnblogs.com/expiator/p/7977975.html 现在尝试使用注解来配置SpringAop. Aop,面向切面编程. ...

随机推荐

  1. (二)boost库之字符串格式化

    (二)boost库之字符串格式化 程序中经常需要用到字符串格式化,就个人而言还是比较倾向于C格式的输出,如果只是打印日志,printf就够了,如果到生成字符串,获取你可以选择sprintf,但这些都是 ...

  2. PDM使用问题总结

    1.连接postgres生成pdm 直接连postgres数据库生成的可以生成表名,但表结构为空,不知为何,后来直接用生成数据库sql脚本后转成pdm成功.但是列注释没有了. 2.sql语句生成的pd ...

  3. linux分区,文件系统,目录结构概述

    1.Linux中如何表示硬盘,分区 Linux内核读取光驱,硬盘等资源时均通过“设备文件”的形式进行,因此在linux系统中,将硬 盘和分区表示为不同的文件.具体表述形式如下: 硬盘:对于IDE接口的 ...

  4. Hadoop权威指南学习笔记二

    MapReduce简单介绍 声明:本文是本人基于Hadoop权威指南学习的一些个人理解和笔记,仅供学习參考,有什么不到之处还望指出,一起学习一起进步. 转载请注明:http://blog.csdn.n ...

  5. 【Quick-COCOS2D-X 3.3 怎样绑定自己定义类至Lua之四】使用绑定C++至Lua的自己定义类

    续[Quick-COCOS2D-X 3.3 怎样绑定自己定义类至Lua之三]动手绑定自己定义类至Lua 之后.我们已经完毕了自己定义类至Lua的绑定.在接下来的环节,我们将使用它. 首先,我们须要确定 ...

  6. 关于AndroidManifest.xml

    一.关于AndroidManifest.xml http://themeforest.net/item/metro-vibes-showcase-html-theme/full_screen_prev ...

  7. sctf pwn400

    这个题目在这个链接中分析得很透彻,不再多余地写了.http://bruce30262.logdown.com/posts/245613-sctf-2014-pwn400 exploit: from s ...

  8. C#实现MD5字符串加密

    public string Md5Encrypt(string str, string str2) { byte[] result = Encoding.Default.GetBytes((str+s ...

  9. 在 Parallels Desktop 中,全屏模式使用 Win7,唤醒时黑屏

    在Parallels Desktop中,全屏模式下使用Win7,如果Mac电脑自动休眠了,则无法再次唤醒了,唤醒时黑屏. 博主的Mac是2014款MBPR,键盘上所有的键都试过,还是无法唤醒电脑,每次 ...

  10. .net 生成缩略图

    public static void CreateSmallImage(string minImageFullPath, System.Drawing.Image originalImage, int ...