日期:2014-05-20  浏览次数:20622 次

精通Spring事务管理的请进!
小弟现在要做这样一件事情:目前项目中用到的开发框架是:SSH,目前想实现监听用户对数据的增加、删除、修改操作,作为日志保存起来。现在的思路是:使用spring的事务监听机制,在Service层对指定的方法做监听。我现在已经做了以下配置:
<bean id="operateListener" class="com.util.listener.OperationListener"></bean>
<aop:config>  
  <aop:aspect id="TestAspect" ref="operateListener">  
  <!--配置com.spring.service包下所有类或接口的所有方法-->  
  <aop:pointcut id="businessService"  
  expression="execution(* com.domain.manager.*.*(..)) and args(...) " />  
  <aop:before pointcut-ref="businessService" method="doBefore"/>  
  <aop:after pointcut-ref="businessService" method="doAfter"/>  
  <aop:around pointcut-ref="businessService" method="doAround"/>  
  <aop:after-throwing pointcut-ref="businessService" method="doThrowing" throwing="ex"/>  
  </aop:aspect>  
</aop:config>  
监听类是:
public class OperationListener
{
public void doAfter(JoinPoint jp) {  
  System.out.println("log Ending method: "  
  + jp.getTarget().getClass().getName() + "."  
  + jp.getSignature().getName());  
  }  
  
  public Object doAround(ProceedingJoinPoint pjp) throws Throwable {  
  long time = System.currentTimeMillis();  
  Object retVal = pjp.proceed();  
  time = System.currentTimeMillis() - time;  
  System.out.println("process time: " + time + " ms");  
  return retVal;  
  }  
  
  public void doBefore(JoinPoint jp) {  
  System.out.println("log Begining method: "  
  + jp.getTarget().getClass().getName() + "."  
  + jp.getSignature().getName());  
  }  
  
  public void doThrowing(JoinPoint jp, Throwable ex) {  
  System.out.println("method " + jp.getTarget().getClass().getName()  
  + "." + jp.getSignature().getName() + " throw exception");  
  System.out.println(ex.getMessage());  
  }  
  


}
但现在一直没有实现监听效果,请高手请教!!!!!!

------解决方案--------------------
<aop:aspect id="testAspect" ref="operateListener">
<!--配置com.spring.service包下所有类或接口的所有方法-->
<aop:pointcut id="businessService"
expression="execution(* com.domain.manager.*.*(..))" />
试试
------解决方案--------------------
我今天搞了一天了,还是没有弄出来,很悲剧,不知道为什么,出异常了就是不回滚,等高手出现,纠结ing。。。
------解决方案--------------------
<aop:pointcut id="businessService"
expression="execution(* com.domain.manager.*.*(..)) and args(...) " />
你这个不对吧, 改成这样试试:
 expression="execution(* com.domain.manager.*.*(..))" 不知道你的包结构是怎样的,这里你在后面的
and args(...) 很是怪异。参数匹配使用前面第一个括号里面的规则。
------解决方案--------------------
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* com.sailing.app.uupms..*.*(..))"