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)面向切面编程.说成切面不容易理解,代码哪里有切面?又不是三维物体.概念不管,我们从其思想来理解这个名 ...
随机推荐
- LeetCode :Word Ladder II My Solution
Word Ladder II Total Accepted: 11755 Total Submissions: 102776My Submissions Given two words (start ...
- Android 中文API (65) —— BluetoothClass[蓝牙]
前言 本章内容是android.bluetooth.BluetoothClass,为Android蓝牙部分的章节翻译.用于描述远端设备的类型,特点等信息,通过getBluetoothClass()方法 ...
- bulk insert data into database with table type .net
1. Create Table type in Sqlserver2008. CREATE TYPE dbo.WordTable as table ( [WordText] [nchar]() NUL ...
- 【转】install intel wireless 3165 driver for ubuntu 14.04.3
[转]install intel wireless 3165 driver for ubuntu 14.04.3 Ubuntu 14.04.3 with 3.19 kernel can’t drive ...
- [译]Stairway to Integration Services Level 3 - 增量导入数据
让我们打开之前的项目:My_First_SSIS_Project_After_Step_2.zip 之前项目中我们已经向dbo.contact 导入了19972行,如果再次执行包会重复导入,让我们来解 ...
- Lowest Common Multiple Plus
Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- Apache+php+mysql+phpadmin搭建
一,准备工具. httpd-2.4.12-win32-VC9.zip php-5.4.40-Win32-VC9-x86.zip phpMyAdmin-4.2.13.2-all-languages my ...
- [LeetCode]题解(python):014-Longest Common Prefix
题目来源: https://leetcode.com/problems/longest-common-prefix/ 题意分析: 这道题目是要写一个函数,找出字符串组strs的最长公共前缀子字符串. ...
- UnixShell编程(第三版)
这本书相当老了,04年的,现在 在linux上做实验. 1,date 显示日期. 2,who 显示用户,who am i 3,echo 后面字符串会全部输出,,会过滤掉多余空格,单双引号,分号等. ...
- Android 一个改进的okHttp封装库
一.概述 之前写了篇Android OkHttp完全解析 是时候来了解OkHttp了,其实主要是作为okhttp的普及文章,当然里面也简单封装了工具类,没想到关注和使用的人还挺多的,由于这股热情,该工 ...