AOP编程
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" default-autowire="byName"> <!-- 配置代理关系 -->
<!-- 目标类 被代理人对象 -->
<bean id="target" class="dao.imp.UserDaoImp"></bean>
<!-- 切面 方面代码(通知代码)-->
<bean id="beforeAdvice" class="aop.BeforeAdvice"></bean> <!-- 代理类 代理人对象-->
<bean id="proxy" class="org.springframework.aop.framework.ProxyFactoryBean"> <!-- 代理用到的接口 拦截者:指明方法代码的封装对象-->
<property name="proxyInterfaces">
<list>
<value>dao.UserDao</value>
</list>
</property> <!-- 目标对象 指明被代理人-->
<property name="target" ref="target">
</property> <!-- 切面 拦截者 :指明方面代码的封装对象 -->
<property name="interceptorNames">
<list>
<!-- <value>beforeAdvice</value> -->
<value>pointcutAndAdvice</value>
</list>
</property>
</bean>
<!-- 配置带切入点的bean
进一步封装代码 ,提供过滤被代理方法的功能 。效果 :被代理接口中方法集合的子集被代理执行-->
<bean id="pointcutAndAdvice" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice" ref="beforeAdvice"></property>
<property name="patterns">
<list>
<value>dao.UserDao.saveUser</value>
<value>dao.UserDao.deleteUser</value>
</list>
</property>
</bean>
</beans>
applicationContext-aop.xml
package aop; import java.lang.reflect.Method;
import org.springframework.aop.MethodBeforeAdvice; public class BeforeAdvice implements MethodBeforeAdvice{ @Override
public void before(Method arg0, Object[] arg1, Object arg2)
throws Throwable {
//arg0 method; arg1参数列表 ; arg2目标对象
// TODO Auto-generated method stub
System.out.println("before");
} }
BeforeAdvice.java
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import dao.UserDao; public class TestAop { public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext ctx=new ClassPathXmlApplicationContext("/applicationContext-aop.xml");
//获取文件
UserDao dao=(UserDao) ctx.getBean("proxy");
//得到代理
dao.saveUser();
dao.deleteUser();
dao.findUser();
} }
测试页面 testaop.java
AOP编程的更多相关文章
- 【原】iOS动态性(三) Method Swizzling以及AOP编程:在运行时进行代码注入
概述 今天我们主要讨论iOS runtime中的一种黑色技术,称为Method Swizzling.字面上理解Method Swizzling可能比较晦涩难懂,毕竟不是中文,不过你可以理解为“移花接木 ...
- 使用spring方式来实现aop编程
1:什么是aop? Aspect Oriented Programming 面向切面编程 在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译 ...
- Spring学习笔记之四----基于Annotation的Spring AOP编程
你能使用@Aspect annotation将某个Java类标注为Aspect,这个Aspect类里的所有公有方法都可以成为一个Advice,Spring提供了5个Annotation去将某个方法标注 ...
- 聊Javascript中的AOP编程
Duck punch 我们先不谈AOP编程,先从duck punch编程谈起. 如果你去wikipedia中查找duck punch,你查阅到的应该是monkey patch这个词条.根据解释,Mon ...
- 基于ASP.NET MVC的热插拔模块式开发框架(OrchardNoCMS)--AOP编程
AOP编程在目前来说好像是大家都比较喜欢的.ASP.NET MVC中的Filter就是使用AOP实现的配置器模式.AOP在编码中的应用主要有如下几个方面: 日志记录,跟踪,优化和监控 事务的处理 持久 ...
- struts2.1笔记03:AOP编程和拦截器概念的简介
1.AOP编程 AOP编程,也叫面向切面编程(也叫面向方面):Aspect Oriented Programming(AOP),是目前软件开发中的一个热点,也是Spring框架中的一个重要内容.利用A ...
- Method Swizzling以及AOP编程:在运行时进行代码注入-备用
概述 今天我们主要讨论iOS runtime中的一种黑色技术,称为Method Swizzling.字面上理解Method Swizzling可能比较晦涩难懂,毕竟不是中文,不过你可以理解为“移花接木 ...
- Aop编程--注解与xml的实现
一.注解方式 1.首先引入spring对于aop编程的jar支持包,spring框架没有的包请自行在网上下载. aopalliance-alpha1.jar aspectjrt.jar aspectj ...
- AOP编程,spring实现及JDK,CGLIB实现
什么是AOP? AOP(Aspect-OrientedProgramming,面向方面编程)和OOP(Object-Oriented Programing,面向对象编程)思想不同,两者并非对立关系,前 ...
- AOP编程和ASP.NET MVC
AOP编程和ASP.NET MVC AOP(Aspect oriented programming)面向切面编程.说成切面不容易理解,代码哪里有切面?又不是三维物体.概念不管,我们从其思想来理解这个名 ...
随机推荐
- 5种方法去掉HTML中Inline-Block元素之间的空白
5种方法去掉HTML中Inline-Block元素之间的空白 记得年轻时我在IE6上开发,绝望的希望IE6能支持display: inline-block功能.当需要在”inline”元素上控制mar ...
- Oracle更改数据库文件大小、实时增加文件容量
--查询数据库文件路径.表空间.大小等 select * from dba_data_files ; --EAST.DBF数据库文件自动扩展20M,可无限扩展 alter database dataf ...
- [Swust OJ 797]--Palindromic Squares(回文数水题)
题目链接:http://acm.swust.edu.cn/problem/797/ Time limit(ms): 1000 Memory limit(kb): 10000 Description ...
- jquery日历签到控件的实现
calendar.js var calUtil = { //当前日历显示的年份 showYear:2015, //当前日历显示的月份 showMonth:1, //当前日历显示的天数 showDays ...
- GROUPING SETS、ROLLUP、CUBE
大家对GROUP BY应该比较熟悉,如果你感觉自己并不完全理解GROUP BY,那么本文不适合你.还记得当初学习SQL的时候,总是理解不了GROUP BY的作用,经过好长时间才终于明白GROUP BY ...
- QT中的qmake详解
关于qmake,好一段时间令我一头雾水,不知道用来干嘛的,只知道怎么用,而且也只懂那么一两个命令,详细看过资料以后整理如下: 1.首先,感性的认识是,qmake可以利用源文件(包括头文件h,实现文件c ...
- 多少遍ner让他加56看6
http://www.huihui.cn/share/8112372 http://www.huihui.cn/share/8112363 http://www.huihui.cn/share/811 ...
- poj 1458 Common Subsequence(区间dp)
题目链接:http://poj.org/problem?id=1458 思路分析:经典的最长公共子序列问题(longest-common-subsequence proble),使用动态规划解题. 1 ...
- strut2服务器与android交互数据
libs如图: web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app versio ...
- Javascript-one
今天,学习Javascript第一天,学习了一些基本的概念,下面就对今天所学的知识进行一个整理,回顾吧! 首先,将Javascript代码包含在(X)html文档中,主要的方法是使用<scrip ...