- 浏览: 798743 次
- 性别:
- 来自: 西安
文章分类
- 全部博客 (307)
- struts (8)
- hibernate (3)
- spring (32)
- opensourceproject (12)
- javaScript (9)
- primeton EOS (2)
- journey of heart (10)
- Design pattern (6)
- ejb (17)
- point (37)
- Linux&Unix (22)
- ibatis (10)
- AJAX (6)
- DB (26)
- Protocol (6)
- chart (4)
- web server (11)
- webservice (7)
- integration (3)
- tuxedo (5)
- ext (4)
- android (1)
- c/c++ (12)
- JVM (1)
- paginationFrame (2)
- code (2)
- report (1)
- High-performance web (1)
- svn (1)
- JQuery (1)
- workDaily (2)
- cloud (16)
- Python (8)
- English (2)
- shell (5)
- googleCode (1)
- nio (1)
- hyper-v (1)
- debug (3)
- vbs (2)
- openstack (3)
- K8S (1)
- Mesos (0)
- Spark (0)
- Marathon (0)
最新评论
-
钱图大展:
chao2751021 写道lib包哪里去下载,找不到
大型网站用户行为记录的一个实现--基于clickStream(第一部分) -
钱图大展:
无法下载
大型网站用户行为记录的一个实现--基于clickStream(第一部分) -
fm395728572:
shell脚本中用到了环境变量,但是获取不到,例如脚本中有一句 ...
ganymed-ssh2 for Java -
liuhanjiang:
我qq147229234
大型网站用户行为记录的一个实现--基于clickStream(第一部分) -
liuhanjiang:
博主 我利用您提供的方法实现博文中介绍的clickstream ...
大型网站用户行为记录的一个实现--基于clickStream(第一部分)
使用Spring AOP 拦截 方法,给被拦截的方法加上,前置通知,后置通知,例外通知,最终通知 的两个例子,见 附件
需要 spring.jar,cglib.jar,commons-logging.jar
方式1. 被拦截的类没有实现任何接口
关键代码:
package junit.test; import org.junit.BeforeClass; import org.junit.Test; import org.springframework.aop.framework.ProxyFactoryBean; import org.springframework.aop.support.DefaultPointcutAdvisor; import cn.com.xinli.common.BusinessMethodInterceptor; import cn.com.xinli.service.BusinessInterface; import cn.com.xinli.service.impl.BusinessImpl; /*springAOP 测试方式1 的测试用例 只需要spring.jar 支持 * * */ public class AOPTest { static BusinessInterface face=null; @BeforeClass public static void setUpBeforeClass() throws Exception { BusinessImpl bi=new BusinessImpl(); ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean(); proxyFactoryBean.setTarget(bi); proxyFactoryBean.addAdvisor(new DefaultPointcutAdvisor(new BusinessMethodInterceptor())); proxyFactoryBean.setInterfaces(new Class[]{BusinessInterface.class}); face= (BusinessInterface)proxyFactoryBean.getObject(); } @Test public void testAdd() throws Exception { face.add(); } @Test public void testDel() { face.del(); } @Test public void testFind() { face.find(); } @Test public void testUpdate() { face.update(); } }
方式2. 被拦截的类没有实现任何接口
关键代码:
package junit.test; import org.junit.BeforeClass; import org.junit.Test; import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.framework.ProxyFactoryBean; import org.springframework.aop.support.DefaultPointcutAdvisor; import cn.com.xinli.common.BusinessMethodInterceptor; import cn.com.xinli.service.impl.Business; /*springAOP 测试方式2 的测试用例 需要spring.jar和cglib.jar 支持 * * */ public class AOPTest2 { static Business business =null; @BeforeClass public static void setUpBeforeClass() throws Exception { /**/ ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean(); proxyFactoryBean.addAdvisor(new DefaultPointcutAdvisor( new BusinessMethodInterceptor())); proxyFactoryBean.setTarget(new Business()); business = (Business) proxyFactoryBean.getObject(); } @Test public void testAdd() throws Exception { /*另一种调用方式*/ Business target = new Business(); ProxyFactory pf = new ProxyFactory(); pf.addAdvice(new BusinessMethodInterceptor()); pf.setTarget(target); Business proxy = (Business) pf.getProxy(); //输出代理对象调用的信息 proxy.add(); } @Test public void testDel() { business.del(); } @Test public void testFind() { business.find(); } @Test public void testUpdate() { business.update(); } }
参考:
http://blog.csdn.net/Jyeafee/archive/2006/01/11/575972.aspx
- springAOP.rar (2.5 MB)
- 下载次数: 26
发表评论
-
hibernatetemplate类使用
2010-03-19 22:25 1181http://115893520.iteye.com/blog ... -
Spring 中的JdbcTemplate使用
2010-03-19 22:11 34791.JdbcTemplate的execute()方 ... -
第30讲--Spring提供的CharacterEncoding和OpenSessionInView功能
2009-09-19 18:24 1765CharacterEncoding: 在web ... -
第29讲--为Spring集成的Hibernate配置二级缓存
2009-09-18 00:29 3370合理的使用缓存策略,往往在web开发中提高性能起到关键 ... -
第28讲--Struts与Spring集成方案2(Spring集成Struts)
2009-09-17 00:57 1603集成步骤: 1.和方案1一样需要在web. ... -
第27讲--Struts与Spring集成方案1(Struts集成Spring)
2009-09-16 08:25 1789Spring2.5+Hibernate3.3+Stru ... -
第25,26讲 --搭建和配置Spring与Hibernate整合的环境
2009-06-21 11:21 1582Spring2.5+Hibernate3.3+Stru ... -
第24讲 --使用Spring配置文件实现事务管理
2009-06-20 23:56 1742采用基于XML方式配置事务 <bean ... -
第23讲 --使用Spring注解方式管理事务与传播行为详解
2009-06-11 23:19 2225事务传播属性 REQUIR ... -
第21,22讲 --搭建和配置Spring与jdbc整合的环境+Spring集成的jdbc编码和事务
2009-06-10 08:06 2677Spring+JDBC组合开发配置数据源有两种方式: ... -
第20讲--aspectj的切入点语法定义细节
2009-06-06 17:47 3620表达式分析: expression=" ... -
第19讲 --使用Spring配置文件实现AOP
2009-06-06 17:21 1519上面我们是使用注解的方式实现spring AOP的,下面 ... -
第18讲 --使用Spring的注解方式实现AOP的细节
2009-06-06 15:48 1532上一讲我们使用spring注解的方式理由aop技术 ... -
第17讲 --使用Spring的注解方式实现AOP入门
2009-06-05 00:48 2248使用Spring进行面向切面(AOP)编程 要 ... -
第16讲 --使用CGLIB实现AOP功能与AOP概念解释
2009-06-04 07:42 1612当代理对象没有实现 ... -
第15讲 --使用JDK中的Proxy技术实现AOP功能
2009-06-04 07:34 2305当目标类实现了接口,我们可以使用jdk的Proxy ... -
第14讲 --让Spring自动扫描和管理Bean
2009-06-02 23:40 8731通过在classpath自动扫描方式把组件纳入sp ... -
第13讲 --Autowire注解与自动装配
2009-06-02 22:46 30981. Autowire 默认是 ... -
第12讲 --编码剖析@Resource注解的实现原理
2009-06-01 23:14 3246在这一讲开始之前,我们先学习一下jdk5.0 中的一个新 ... -
第11讲 --用@Resource注解完成属性装配
2009-05-31 22:42 7009bean的注入方式有3种: 第一种:使用构造器注 ...
相关推荐
死磕Spring之AOP篇 - Spring AOP两种代理对象的拦截处理(csdn)————程序
spring aop demo 通过注解和配置文件的两种实现方式 包含jar包 下载直接运行
sring aop的方式有两种:(1)xml文件配置方式(2)注解的方式实现,我们可以先通过一个demo认识spring aop的实现,然后再对其进行详细的解释。
AOP的意思就是面向切面编程。本文主要是通过梳理JDK中自带的反射机制,实现 AOP动态代理模式,这也是Spring AOP 的实现原理
Spring AOP 使用的动态代理主要有两种方式:JDK 动态代理和 CGLIB 代理。 JDK 动态代理:用于代理实现了接口的类。Spring 会使用 java.lang.reflect.Proxy 类来创建代理对象。 CGLIB 代理:用于代理没有实现接口的...
SpringAOP的注解配置完成切面的编程,完成execution,annotation两种表达式的实例Ddemo
详细讲解了aop的xml配置和注解的方式配置,和本人的博客想应
主要为大家详细介绍了spring aop两种配置方式,主要是注解配置AOP和xml配置aop,需要的朋友可以参考下
spring-aop标签和配置文件两种方式实例,spring要求2.5及以上
SpringAop实例,包括xml和配置两种方式.jar齐全
3、了解Spring中两种动态代理方式的区别; 4、掌握基于XML和注解的AspectJ开发。 二、 实验内容 1、按图所示的类图结构,设计接口及其实现类,并完成另外两附加要求:(1)日志功能:在程序执行期间追踪正在发生的...
本资源将深入探讨Spring框架中使用的两种关键的动态代理方式:JDK动态代理和CGLib动态代理。这两种代理方式在Spring AOP中起到关键作用,用于实现横切关注点的切面编程。通过学习它们的原理和实际应用,您将能够更好...
Spring 使用AspectJ 实现 AOP(基于xml文件、基于注解)
SpringAOP与SpringMVC拦截器两种方式实现权限管控,前台xml读取配置根据登录用户判断button是否enable
SpringAop配置事务管理,有两种配置方式。一种直接使用注解的方式,另外一种非注解
写了SpringAop的两种代理的实现,jdk动态代理和cglib代理的代码,及测试。
有关于Spring,我们最常用的两个功能就是IOC和AOP,前几篇文章从源码级别介绍了Spring容器如何为我们生成bean及bean之间的依赖关系... 确实,Spring也就是通过这两种方式来实现AOP相关功能,下面就通过源码来简单求证下
java手动实现、注解方式实现两种方法实现springaop编程,包含源码+jar包+解释
所以从本文开始介绍@Pointcut切点表达式,虽然Spring AOP的切点表达式尚未 全部实现 @AspectJ 的切点指示符,但是也已经足够多和灵活,本文主要介绍@Pointcut切点表达式中的@within、within这两种切点指示符,结合...