首页 新闻 赞助 找找看

S2SH集成中使用AOP后查询结果为NULL?。。请教高手解答一下

0
悬赏园豆:5 [已解决问题] 解决于 2013-06-07 17:49

做SSH集成,用得是spring的声明式事务和hibernate做的集成。
以下是spring配置文件中关于AOP的配置:

<!-- 配置aop拦截声明类 -->
<bean id = "myAop" class="com.acc.aop.MyAop"></bean>
<aop:config>
  <aop:pointcut expression="execution(* com.acc.service.*.*(..))" id="pointCut"/>
  
<aop:advisor advice-ref="txAdvice" pointcut-ref="pointCut"/>
<!-- 配置切面 --> <aop:aspect id="aspect" ref="myAop"> <aop:after method="after" pointcut-ref="pointCut"/> <aop:after-returning method="afterReturning" pointcut-ref="pointCut"/> <!--环绕 --> <aop:around method="arroundAdvice" pointcut-ref="pointCut"/> <aop:before method="beforeAdvice" pointcut-ref="pointCut"/> </aop:aspect> </aop:config>

之后是从Dao 层 ---》service层----》action层逐层注入的,在action中查询结果集,调用注入在action层中的service层接口,执行数据查询操作时,查询的结果为NUll!!!!
我试了一下把上面配置文件中的<aop:aspect id="aspect" ref="myAop"></sop:aspect>标签中配置的环绕通知配置项注释掉后,可以查询出结果集.
一下是自定义的aop类中的环绕方法:com.acc.aop.MyAop -->这个类中的方法

public void arroundAdvice(ProceedingJoinPoint pjp){
System.out.println("环绕通知");
try {
pjp.proceed();
} catch (Throwable e) {
e.printStackTrace();
}
}

 

为什么注释了配置文件中有关于环绕通知的配置后就可以查询出结果集了??

<!--环绕 -->
<aop:around method="arroundAdvice" pointcut-ref="pointCut"/>

 

不懂了,恳请各位帮忙解决!

AaronChun的主页 AaronChun | 初学一级 | 园豆:152
提问于:2013-06-03 15:36
< >
分享
最佳答案
0

 Spring里的通知类型 有:1,拦截around通知。2,前置通知。3,异常通知。4,后置通知 5,引入通知。

五种通知类型,你只需要一种即可!

在Spring中最基础的通知类型是拦截around通知。实现around通知的MethodInterceptor应当实现下面的接口:

public interface MethodInterceptor extends Interceptor {
  
    Object invoke(MethodInvocation invocation) throws Throwable;
}
所以说你只需要选择一种通知类型!
 <aop:around 
     <aop:before  像这样你指定了两个通知类型!当你注释掉一个当然可以了啊!
收获园豆:5
Beyond-bit | 老鸟四级 |园豆:2885 | 2013-06-03 16:27

你好,你说的这种配置方式应该是用proxy工厂模式下配置的吧,我现在用得时AOP的aspect去拦截的,写的拦截类不用继承什么接口的,只不过有一个ProceedJoinPoint pjp 这么一个连接点,执行pjp.proceed();方法就可以了。
我对这块也不是很清楚,就像你说的,实际应用是只需要选择一种通知类型就行吗?能解决所有的问题吗?比方说我既想在方法执行之前(before)打印日志,也想在方法彻底执行完(after-returning)之后再次打印日志,可不可以声明两个通知类型???

谢谢!!!

AaronChun | 园豆:152 (初学一级) | 2013-06-03 16:39

@大艾黑天: 比方说我既想在方法执行之前(before)打印日志,也想在方法彻底执行完(after-returning)之后再次打印日志?那你只需要声明一个around 通知即可,这个通知就是执行前,执行后都会去做的!

 

Beyond-bit | 园豆:2885 (老鸟四级) | 2013-06-03 17:08

@大艾黑天: 

<!-- AOP配置 -->
<aop:config>
<!-- 切面 -->
<aop:aspect id="myAspect" ref="myAop"> 

<aop:pointcut id="myAnyMethod"
expression="execution(* xx.xxx.service.imple.*.*(..))" />
<aop:before pointcut-ref="myAnyMethod" method="通知的方法"/>
<aop:after-returning method="通知的方法" pointcut-ref="myAnyMethod" returning="returnArg"/>
<aop:after-throwing method="通知的方法" pointcut-ref="myAnyMethod" throwing="ex"/>
<aop:after method="通知的方法" pointcut-ref="myAnyMethod"/>
<aop:around method="环绕通知的方法" pointcut-ref="myAnyMethod"/><!--你只需要这个环绕方法就可以得到你想要的前后通知,上面的几种是不同的通知类型!-->

</aop:aspect>
</aop:config>

Beyond-bit | 园豆:2885 (老鸟四级) | 2013-06-03 17:22
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册