做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类中的环绕方法:
public void arroundAdvice(ProceedingJoinPoint pjp){
System.out.println("环绕通知");
try {
pjp.proceed();
} catch (Throwable e) {
e.printStackTrace();
}
}
为什么注释了配置文件中有关于环绕通知的配置后就可以查询出结果集了??
<!--环绕 -->
<aop:around method="arroundAdvice" pointcut-ref="pointCut"/>
不懂了,恳请各位帮忙解决!
当使用环绕通知时,你的代码会在被通知的方法的调用之前和之后执行。这个通知可以在方法调用之前进行预处理,也可以在方法返回之后进行清理工作。
具体来说,当你的代码中使用了环绕通知时,环绕通知的方法会在被通知的方法之前执行,然后调用被通知的方法,最后再执行环绕通知的方法。
在你的代码中,你可以使用 ProceedingJoinPoint 类型的参数 pjp 来调用被通知的方法。你需要在环绕通知的方法中调用 pjp.proceed() 来执行被通知的方法。
如果你在环绕通知的方法中没有调用 pjp.proceed(),那么被通知的方法就不会被执行,因此你可能会得到一个空结果集。
建议你检查一下在注释掉环绕通知的情况下,你的被通知的方法是否正常执行,并确保在环绕通知的方法中调用了 pjp.proceed()。