Spring AOP对嵌套方法不起作用
来源:互联网 发布:英文信件结尾知乎 编辑:程序博客网 时间:2024/06/08 17:06
Spring AOP有一个限制,它对嵌套方法调用不起作用。究其原因,是因为Spring aop是作用在spring beans上,而不是作用于实际的类的实例。举例来说:
比如我按如下方法配置了一个aspect,
<beanclass="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator" /><bean id="positionAspect"class="com.MyPositionUpdateAspect"/>
在这个aspect里(使用aspectj的语法支持),我配置了我的pointcut,意思是对MyTradeProcessor的所有方法调用(正常返回的)进行拦截。
package com;@Aspectpublic class MyPositionUpdateAspect {@AfterReturning(value = "execution(* com.MyTradeProcessor.*(..))", returning = "retTrade")public void updatePosition(JoinPoint joinPoint, Object retTrade) throws Throwable { // my business logic }}
下面是MyTradeProcessor类的大致框架:
public class MyTradeProcessor { public ITrade amend(ITrade inputTrade) throws TradeBookingException { if (isAmendForTemp) return newTrade(inputTrade); } // other logic }public ITrade newTrade(ITrade inputTrade) throws TradeBookingException { // newTrade logic }}
还有一种解决办法是利用aspectj weaving。大致的配置如下,详细的说明可以参考http://stackoverflow.com/questions/5780757/spring-aop-logging-and-nested-methods。
<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd"> <aspectj> <weaver options="-Xset:weaveJavaxPackages=true -verbose -showWeaveInfo -debug"> <include within="*"/> </weaver> <aspects> <!-- weave in just this aspect --> <aspect name="your.logger.impl.LoggingImpl"/> </aspects> </aspectj>This implies weaving in all your files ('within=*', modify as you wish) with the aspect/s specified. On load time you should see verbose information on weaving of classes.
<context:load-time-weaver aspectj-weaving="autodetect" weaver-class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver"/>
- Spring AOP对嵌套方法不起作用
- Spring AOP对嵌套方法不起作用
- Spring AOP切面对Controller中的方法切点不起作用
- Spring AOP 对Spring MVC的Controller切面拦截不起作用
- Spring 嵌套事务不起作用
- spring aop 事务不起作用
- Spring Aop不起作用
- 解决Spring MVC 对AOP不起作用的问题
- 解决Spring MVC 对AOP不起作用的问题
- 解决Spring MVC 对AOP不起作用的问题
- 解决Spring MVC 对AOP不起作用的问题
- 解决Spring MVC 对AOP不起作用的问题
- Spring AOP 嵌套AOP
- spring aop事物管理不起作用
- Spring AOP嵌套调用
- spring aop之对象内部方法间的嵌套失效
- spring aop之对象内部方法间的嵌套失效
- spring aop 无法在内部嵌套的方法上生效
- Android Density[转] +Gentoo中的系统时间调整[转]
- Gentoo Linux nVidia Guide
- Gentoo Linux 内核更新指南
- 代码覆盖率工具,以后慢慢研究
- hdu 1027 ignatius and the princess ii
- Spring AOP对嵌套方法不起作用
- java JFrame 关闭窗口时确认
- java.sql.Date与java.sql.TimeStamp
- 一个在dos系统下的USB库
- SAXBulider基本用法
- 编程技术面试的五大要点
- [Mac]在 Mac 上开发 .Net 应用
- Gentoo Linux x86快速安装指南
- Enterprise Architect 8之数据建模(创建索引)