首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为Couchbase应用程序添加事务管理器。在用于Junit测试的SpringBoot 2应用程序中

为Couchbase应用程序添加事务管理器。在用于Junit测试的SpringBoot 2应用程序中
EN

Stack Overflow用户
提问于 2019-10-22 15:07:01
回答 1查看 458关注 0票数 3

我有一个Spring2应用程序,它使用SpringBoot作为数据库和Spring Data Couchbase

我想要在测试中添加一个事务管理器来添加注释@Transactional来执行回滚,否则我会得到这个错误:

代码语言:javascript
复制
java.lang.IllegalStateException: Failed to retrieve PlatformTransactionManager for @Transactional test: [DefaultTestContext@3bf9ce3e testClass = RequestServiceIntegrationTest, testInstance = com.pxs.rqm.requestcrud.service.RequestServiceIntegrationTest@1ebcfcf1, testMethod = shouldSaveWhenDataIsOK@RequestServiceIntegrationTest, testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@16610890 testClass = RequestServiceIntegrationTest, locations = '{}', classes = '{class com.pxs.rqm.requestcrud.Application}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@971d0d8, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@564718df, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@36f0f1be, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@2145433b], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true, 'org.springframework.test.context.web.ServletTestExecutionListener.populatedRequestContextHolder' -> true, 'org.springframework.test.context.web.ServletTestExecutionListener.resetRequestContextHolder' -> true]]

    at org.springframework.util.Assert.state(Assert.java:94)
    at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethod(TransactionalTestExecutionListener.java:185)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-23 22:30:59

尽管我们试图支持大多数Spring接口,但@Transactional接口是特定于关系型数据库的。

Couchbase中的更新是原子的(要么全部更新,要么什么都不更新),并且由于数据建模的方式与关系不同,您通常不需要经常使用事务。例如,以用户为例,与其相关的所有数据(首选项、地址、信用卡)都将存储在同一文档中,这就是为什么在这种情况下交易通常是不必要的。

然而,如果您需要同时更新多个文档,那么您可以考虑使用目前仅在SDK3上提供的新的事务支持(https://www.couchbase.com/transactions)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58498795

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档