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,面向切面编程. ...
随机推荐
- SSAS-时间维度的标准设计
1.首先要构建一个时间维度表,下面给出通用的构建时间维度的存储过程: USE [BI_DW] GO /****** Object: StoredProcedure [dbo].[proc_Dim_da ...
- PyCharm设置字体
pycharm 是很好的一个IDE,就是默认字体太小了,真的太小了,改字体的地方很隐晦.找了半天,贴图: 然后发现size 不能更改,所以,点击save as创建一个方案,然后修改自己的方案.这个时候 ...
- UVALive 6665 Dragonas Cruller
题目链接:https://icpcarchive.ecs.baylor.edu/external/66/6665.pdf 题目大意: 有一个3 * 3 的格子: 每个格子上面的数字能够朝上下左右四个方 ...
- iOS 各种传值方式
属性传值 将A页面所拥有的信息通过属性传递到B页面使用 B页面定义了一个naviTitle属性,在A页面中直接通过属性赋值将A页面中的值传到B页面. A页面DetailViewController.h ...
- JQ调用后台方法
首先,先在页面上创建一个asp按钮,添加点击事件,把要在前台调用的后台方法写在这个按钮的点击事件中: <span style="display:none;"><a ...
- SET STATISTICS IO和SET STATISTICS TIME 在SQL Server查询性能优化中的作用
近段时间以来,一直在探究SQL Server查询性能的问题,当然也漫无目的的查找了很多资料,也从网上的大神们的文章中学到了很多,在这里,向各位大神致敬.正是受大神们无私奉献精神的影响,所以小弟也作为回 ...
- JavaScript function函数种类(转)
转自:http://www.cnblogs.com/polk6/p/3284839.html JavaScript function函数种类 本篇主要介绍普通函数.匿名函数.闭包函数 目录 1. 普通 ...
- C# 5 break continue 球员成绩 彩票 选班长
二.新课: 1.break与continue. 这两个关键字一般放在循环的花括号里面使用. break--结束整个循环. continue--结束本次循环,进入下次循环. break的案例: ...
- form表单中经常用到的禁用获取值问题
<input name="country" id="country" size=12 value="disabled提交时得不到该值 " ...
- Ubuntu package managerment tools
Visual demostration References Understanding differences between dpkg and apt-get/aptitude tools. A ...