Could not obtain transaction-synchronized Session for current thread 错误记录

今天在老项目上测试新的功能,不能在原有的业务层上继续添加业务代码,因此,新建了一层业务层,如下图:
在这里插入图片描述
之后的代码基本上都是按照标准的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>

之后再调用后就没问题了。
以前好像遇到过这个问题,这次就做个记录方便以后查看。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值