今天在老项目上测试新的功能,不能在原有的业务层上继续添加业务代码,因此,新建了一层业务层,如下图:
之后的代码基本上都是按照标准的copy过来,项目启动正常,不过在调用其他功能后,在这一段代码中报了异常:
Session session = getSession();
异常信息如下:
查了下资料,应该是获取session的方法不在事务管理器内,查看一下配置文件如下:
<aop:config expose-proxy="true">
<!-- 只对业务逻辑层实施事务 -->
<aop:pointcut id="txAuthPointcut"
expression="execution(* com.*.services.*.*(..))" />
<!-- Advisor定义,切入点和通知分别为txPointcut、txAdvice -->
<aop:advisor pointcut-ref="txAuthPointcut" advice-ref="txAdvice" />
</aop:config>
把新建的业务层贴上去就可以了,如下:
<aop:config expose-proxy="true">
<!-- 只对业务逻辑层实施事务 -->
<aop:pointcut id="txAuthPointcut"
expression="execution(* com.*.services.*.*(..))" />
<aop:pointcut id="txTest"
expression="execution(* com.*.service.*.*(..))" /><!-- 新方法测试-->
<!-- Advisor定义,切入点和通知分别为txPointcut、txAdvice -->
<aop:advisor pointcut-ref="txAuthPointcut" advice-ref="txAdvice" />
<aop:advisor pointcut-ref="txTest" advice-ref="txAdvice" /> <!-- 新方法测试 -->
</aop:config>
之后再调用后就没问题了。
以前好像遇到过这个问题,这次就做个记录方便以后查看。