新建一个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. USB device & USB controller & USB passthrough

    目录 USB device USB controller Linux 相关命令 Python 相关库 Libvirt USB passthrough 参考资料 近期往 openstack 里倒腾 US ...

  2. centos Ddos防范开源软件使用及apache ab压测 测试

    1,检索特定字符的相同行,用于过滤点一些命令行的头说明

  3. Binary Tree Level Order Traversal - leetcode - java

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...

  4. hdu 2660 Accepted Necklace(dfs)

    Problem Description I have N precious stones, and plan to use K of them to make a necklace for my mo ...

  5. KMP快速模式匹配的java实现

    假期实在无聊赖啊.把这个算法实现了一下即算是打发时间也算练练手了. KMP算法的关键是用归纳法计算失败函数.网上很详细了.下面直接给出代码. /** * * @author Vincent * */ ...

  6. IOS 开展 分别制定了iphone 和 ipad 好? 或开发一个 Universal好?

    最近因为工作的需要,.因为时间短的开发周期 开发的需要 积 至iphone 和 ipad 台 执行 优势的版本号 1.安装包,轻松管理,分布 2.您下载iphone,ipad 会自己主动下载 3.审核 ...

  7. Hortonworks HDP Sandbox定制(配置)开机启动服务(组件)

    定制Hortonworks HDP开机启动服务能够这样做:本文原文出处: http://blog.csdn.net/bluishglc/article/details/42109253 严禁不论什么形 ...

  8. C#关于事件的几个好例子

    #region // 定义BoiledEventArgs类,传递给Observer所感兴趣的信息 public class BoiledEventArgs : EventArgs { public r ...

  9. javascript设计模式——Publish/Subscribe

    推荐阅读http://dev.housetrip.com/2014/09/15/decoupling-javascript-apps-using-pub-sub-pattern/ 我们先引出问题的所在 ...

  10. CSS中为什么overflow:hidden能清除浮动(float)的影响?原理是什么?

    http://www.zhihu.com/question/30938856 父块没有设置指定的高宽,当子块设置为浮动后,原本包裹子块的父块的高度塌陷消失,这时给父块设置overflow:hidden ...