Spring、XML配置AOP
新建一个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的更多相关文章
- 2015年12月10日 spring初级知识讲解(二)最小化Spring XML配置 注解
序,随着Spring容器管理Bean数量增加,XML文件会越来越大,而且纯手工配置XML很繁琐,Spring和JAVA都提供了一些注解方式用以简化XML配置. 目录 一.自动装配(autowiring ...
- spring xml配置注入改为手动注入过程
项目中需要使用MQ组件来接受消息,但是有的时候,在使用的时候,并不能满足spring注入的条件,无法注入.例如 在jfinal的config的afterJFinalStart中,由于jfinal集成s ...
- springAop:Aop(Xml)配置,Aop注解配置,spring_Aop综合案例,Aop底层原理分析
知识点梳理 课堂讲义 0)回顾Spring体系结构 Spring的两个核心:IoC和AOP 1)AOP简介 1.1)OOP开发思路 OOP规定程序开发以类为模型,一切围绕对象进行,OOP中完成某个任务 ...
- 最小化Spring XML配置
Spring提供两种技巧,可以帮助我们减少XML的配置数量. 1.自动装配(autowiring)有助于减少甚至消除配置<property>元素和<constructor-arg&g ...
- Spring XML配置里的Bean自动装配
Spring自动装配 这段是我们之前编写的代码,代码中我们使用了P命名空间 并且使用手动装配的方式将car <bean id="address" class="cn ...
- Spring 使用xml配置aop
1.xml文件需要引入aop命名空间 2.xml内容: <?xml version="1.0" encoding="UTF-8"?> <bea ...
- Spring XML配置实现AOP
1: 首先我们要定义 配置成切面的类 package cn.gbx.example; import org.aspectj.lang.ProceedingJoinPoint; import org. ...
- Spring基于XML配置AOP
目录结构: D:\Java\IdeaProjects\JavaProj\SpringHelloWorld\src\cn\edu\bjut\service\StudentService.java pac ...
- Spring注解配置Aop
之前学习了SpringAop的基本原理.http://www.cnblogs.com/expiator/p/7977975.html 现在尝试使用注解来配置SpringAop. Aop,面向切面编程. ...
随机推荐
- 如何让FPGA中的SPI与其他模块互动起来
在上一篇文章<FPGA的SPI从机模块实现>中,已经实现了SPI的从机模块,如何通过SPI总线与FPGA内部其他模块进行通信,是本文的主要讨论内容. 一. 新建FPGA内部DAC控制模块 ...
- 【LeetCode练习题】Longest Valid Parentheses
Longest Valid Parentheses Given a string containing just the characters '(' and ')', find the length ...
- -DDEBUG编译标记
想必大家都有利用输出函数如printf来帮助我们调试程序的经历,这是一种比较原始的程序调试辅助方法,在Linux下也可以为我们所用.不过这种方法有一个明显的缺点,就是在调试完后我们必须注释或删除掉这些 ...
- nodejs面试
1. PM2相关 1. PM2的主要功能?*答案:在Node.js进程挂掉以后自动重启进程,并且能够方便的实现Node.js的集群模式* 2. 如何查看当前是否适合重启服务?*答案:pm2 monit ...
- H264源码分析(二)
原文出自http://blog.csdn.net/xfding/article/details/5476763(转载收集) (四)图像参数集语义 pic_parameter_set_rbsp( ) { ...
- HDU 1757 A Simple Math Problem(矩阵高速幂)
题目地址:HDU 1757 最终会构造矩阵了.事实上也不难,仅仅怪自己笨..= =! f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + -- + a9 ...
- C#版QQTea加密
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Wind ...
- 微信朋友圈分享js代码最新2015年无错版
最近微信对分享做了进一步规范,导致很多分享都不起作用了,今天跟大家分享,2015年最新修无错的! 以下是主要微信分享页面代码:(其中红色部分主要懒友自己填写自己哈.) <?php require ...
- mysql的面试试题
1, mysql的复制原理以及流程. (1)先问基本原理流程,3个线程以及之间的关联. 答:Mysql复制的三个线程:主库线程,从库I/O线程,从库sql线程: 复制流程:(1)I/O线程向主库发出请 ...
- 页面样式base.css
下面是我用过多次的base.css.欢迎各种建议吐槽.大家共同进步. ;;} table{;} fieldset,img {;} address,caption, cite,code,dfn,em,s ...