spring+ibatis+junit调用存储过程,事务不提交(rolled back)

在用junit进行单元测试时,调用sql server库的存储过程,会报如下问题,即事务自动回滚:
10:44:56.682 [main] WARN  - Unable to proxy method [public final void org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests.setApplicationContext(org.springframework.context.ApplicationContext)] because it is final: All calls to this method via a proxy will NOT be routed to the target instance.
10:44:56.777 [main] INFO  - Began transaction (1) for test context [DefaultTestContext@54b07eeb testClass = DeviceControllerTest, testInstance = com.tonson.app.push.api.user.DeviceControllerTest@f5ca1bd, testMethod = testClientSetting@DeviceControllerTest, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@a7e872c testClass = DeviceControllerTest, locations = '{classpath:spring/applicationContext.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]]; transaction manager [org.springframework.jdbc.datasource.DataSourceTransactionManager@78dc5f15]; rollback [true]
10:44:56.793 [main] DEBUG - {conn-100000} Connection
10:44:56.820 [main] DEBUG - {conn-100000} Preparing Call: {call UP_UserConfig_Save1 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}
10:44:56.846 [main] DEBUG - {pstm-100001} Executing Statement: {call UP_UserConfig_Save1 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}
10:44:56.846 [main] DEBUG - {pstm-100001} Parameters: [0, 111, 111, 2, 111, 0, 111, 1, 1, 815, 1445, 111]
10:44:56.847 [main] DEBUG - {pstm-100001} Types: [java.lang.Integer, java.lang.String, java.lang.String, java.lang.Integer, java.lang.String, java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.String]
{"lan":false,"message":"成功","returncode":0}
10:44:56.984 [main] INFO  - Rolled back transaction after test execution for test context [DefaultTestContext@54b07eeb testClass = DeviceControllerTest, testInstance = com.autohome.app.push.api.user.DeviceControllerTest@f5ca1bd, testMethod = testClientSetting@DeviceControllerTest, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@a7e872c testClass = DeviceControllerTest, locations = '{classpath:spring/applicationContext.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]]
10:44:56.988 [Thread-1] INFO  - Closing org.springframework.context.support.GenericApplicationContext@79ed3030: startup date [Sat Oct 24 10:44:54 CST 2015]; root of context hierarchy

如果此时测试的本意是要更新库里数据,则需要在对应测试的方法上加注解:@Rollback(false),如:

@Test
@Rollback(false)//防止事务自动回滚
public void testClientSetting(){
}
当然,在使用事务相关注解时,需要声明式事务,即在applicationContext.xml文件中添加:

<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="false" />
	 
<!-- 定义事务 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
	<property name="dataSource" ref="pushApiDataSource" />
</bean>



  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值