- 浏览: 798785 次
- 性别:
- 来自: 西安
文章分类
- 全部博客 (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(第一部分)
表达式分析:
expression="execution(* cn.com.xinli.service.impl.PersionServiceBean.*(..))"
1.第一个星号表示 拦截方法的返回值为任意
如果为 java.lang.String 表示只拦截 返回值为String的方法
如果为 void 则表示只拦截 返回值为 void 的方法
如果为 !void 则表示只拦截 返回值 非 void的方法
2. 如果我们只拦截 方法第一个参数为String,剩下的参数类型任意 则可以
expression="execution(java.lang.String cn.com.xinli.service.impl.PersionServiceBean.*(java.lang.String,..))"
未处理的问题:
基于配置实现aop的方式 如何给各种通知传递参数,比如给前置通知传递方法的入参,给后置通知传递方法的返回值,等晚上发了版本在研究,基于注解的已经实现了.
处理遗留问题:基于注解的方式实现在前置置通知得到拦截方法的入参,在置通知得到拦截方法的返回值,谢谢楼下的 windywindy 帮助,表示感谢!!
首先在beans.xml中配置切面,拦截表达式,各种通知的定义。。。
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <aop:aspectj-autoproxy proxy-target-class="true"/> <!--切面和业务bean都需要交给容器管理--> <bean id="myInterceptor" class="cn.com.xinli.service.MyInterceptor"></bean> <bean id="personService" class="cn.com.xinli.service.impl.PersionServiceBean"></bean> <aop:config> <!-- 定义一个切面 --> <aop:aspect id="asp" ref="myInterceptor"> <!-- 定义切入点,定义拦截表达式,前置通知,后置通知,等.. --> <aop:pointcut id="mycut" expression="execution(* cn.com.xinli.service.impl.PersionServiceBean.*(..))and args(name)"/> <aop:before pointcut-ref="mycut" method="doAccessCheck" arg-names="name"/> <aop:after-returning pointcut-ref="mycut" method="doAfterReturning" returning="result"/> <aop:after-throwing pointcut-ref="mycut" method="doAfterThrowing"/> <aop:after pointcut-ref="mycut" method="doAfter"/> <aop:around pointcut-ref="mycut" method="doBasicProfiling"/> </aop:aspect> </aop:config> </beans>
1.前置置通知得到拦截方法的入参,关键就是在前置方法中定义一个连接点,从连接点中得到入参,如果有多个则可以用便利的方式得到。 测试调用 ps.save("huxl");
public void doAccessCheck(JoinPoint joinPoint) { System.out.println("前置通知:"); Object[] args = joinPoint.getArgs(); for (int i=0; i<args.length; i++) { System.out.println("入参:"+args[i]); } }
结果:
入参:huxl
进入方法
我是save()方法
后置通知中得到结果:null
最终通知
退出方法
2.在后置通知中得到拦截方法的返回值 关键在与给在配置文件中 给后置方法配置返回的参数,在后置方法中将返回参入当做入参传递 测试 ps.getPersonName(1);
public void doAfterReturning(String result) {
System.out.println("后置通知中得到结果:"+result);
}
结果:
前置通知:
入参:1
进入方法
我是getPersonName()方法
后置通知中得到结果:xxx
最终通知
退出方法
评论
哈哈~
public class XMLInterceptor { public void doAccessCheck(JoinPoint joinPoint,Integer name) { System.out.println("前置通知--"+name); Object[] args = joinPoint.getArgs(); for (int i=0; i<args.length; i++) { System.out.println("---"+args[i]); } System.out.println(joinPoint.getSignature().getName()); } public void doAfterReturning(Person person) { System.out.println("后置通知="+person.getName()); } public void doAfter() { System.out.println("最终通知"); } public void doAfterThrowing() { System.out.println("例外通知"); } public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable { System.out.println("进入方法"); Object result = pjp.proceed(); System.out.println("退出方法"); return result; } }<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <context:component-scan base-package="com"/> <bean id="person" class="com.pojo.Person"/> <aop:aspectj-autoproxy proxy-target-class="true"/> <bean id="xmlInterceptor" class="com.aop.XMLInterceptor"/> <bean id="personService" class="com.service.PersonService"/> <aop:config> <aop:pointcut id="mycut" expression="execution(* com.service..*.*(..)) "/> <aop:pointcut id="argcut" expression="execution(* com.service.PersonService.*(..)) and args(name)"/> <aop:pointcut id="personcut" expression="execution(* com.service.PersonService.*(..)) and args(person)"/> <!-- 定义一个切面 --> <aop:aspect id="asp" ref="xmlInterceptor"> <aop:before pointcut-ref="argcut" method="doAccessCheck" arg-names="name" /> <aop:after-returning pointcut-ref="personcut" method="doAfterReturning" arg-names="person" /> <aop:after-throwing pointcut-ref="mycut" method="doAfterThrowing"/> <aop:after pointcut-ref="mycut" method="doAfter" /> <aop:around pointcut-ref="mycut" method="doBasicProfiling"/> </aop:aspect> </aop:config> </beans>public class Person { private int age; private String name; public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getName() { return name; } public void setName(String string) { this.name = string; } } 测试自己写吧!
发表评论
-
hibernatetemplate类使用
2010-03-19 22:25 1182http://115893520.iteye.com/blog ... -
Spring 中的JdbcTemplate使用
2010-03-19 22:11 34791.JdbcTemplate的execute()方 ... -
SpringAOP 的使用(两种方式)
2009-10-22 13:42 1486使用Spring AOP 拦截 方法,给被拦截的 ... -
第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 1743采用基于XML方式配置事务 <bean ... -
第23讲 --使用Spring注解方式管理事务与传播行为详解
2009-06-11 23:19 2226事务传播属性 REQUIR ... -
第21,22讲 --搭建和配置Spring与jdbc整合的环境+Spring集成的jdbc编码和事务
2009-06-10 08:06 2677Spring+JDBC组合开发配置数据源有两种方式: ... -
第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 2249使用Spring进行面向切面(AOP)编程 要 ... -
第16讲 --使用CGLIB实现AOP功能与AOP概念解释
2009-06-04 07:42 1613当代理对象没有实现 ... -
第15讲 --使用JDK中的Proxy技术实现AOP功能
2009-06-04 07:34 2306当目标类实现了接口,我们可以使用jdk的Proxy ... -
第14讲 --让Spring自动扫描和管理Bean
2009-06-02 23:40 8732通过在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种: 第一种:使用构造器注 ...
相关推荐
sentinel-annotation-aspectj-1.4.0.jar
跟我学Spring3(6.5)AspectJ切入点语法详解Java开发Java经验技巧共10页.pdf.zip
sentinel-annotation-aspectj-1.8.6.jar 如果下载不了,关注我,评论区联系我。
Spring4 In Action-4.2-@AspectJ-切面,Spring4 In Action-4.2-@AspectJ-切面。Spring4 In Action-4.2-@AspectJ-切面
AspectJ Building AspectJ has a multi module maven build. Although various modules produce intermediate results, the key artifacts at the end of the build are: aspectjrt - the AspectJ runtime ...
SpringAOPAspectJ切入点语法详解
gradle-kotlin-aspectj-weaver:一个Gradle插件,可让您使用AspectJ编织已编译的Java和Kotlin文件
Aspect-Oriented Programming with AspectJ
aspectj-1.7.0.jar aspectj的包
自制CHM版的API文档,带索引。 注:如果各位下载后打开或无法显示页面,请在CHM文件右键—属性—解除锁定即可。
包含学习Spring AOP以及学习Spring Aspect J需要新增的jar包,需要的朋友可以下载哦!
NULL 博文链接:https://wangxinchun.iteye.com/blog/2074475
NULL 博文链接:https://wangxinchun.iteye.com/blog/2074483
中文-英文对照文档,中英对照文档,java,jar包,Maven,第三方jar包,组件,开源组件,第三方组件,Gradle,中文API文档,手册,开发手册,使用手册,参考手册 # 使用方法: 解压 【***.jar中文文档.zip】,再解压其中的 【***-...
java-aop-aspectj-demo
build时出现错误Could not resolve nl.eveoh:gradle-aspectj:1.6。将此文件放入此目录下即可.m2\repository\nl\eveoh\gradle-aspectj\1.6
android-gradle-aspectj:gradle插件在Android项目中添加了对AspectJ的支持
sbt-aspectj 插件与编织。 此插件需要sbt 0.13.5+。 添加插件 将插件添加到project/plugins.sbt 。 例如: addSbtPlugin("com.lightbend.sbt" % "sbt-aspectj" % "{version}") 请参阅。 注意:较早版本的sbt-...
aspectj-1.9.1.jar和aspectj-1.9.1.src.jar包。用于切面编程。 aspectj-1.9.1.jar和aspectj-1.9.1.src.jar包。用于切面编程。 aspectj-1.9.1.jar和aspectj-1.9.1.src.jar包。用于切面编程。 原来积分太高,我现在...
解压->运行->下一步->结束