如何在反应式couchbase世界中将文档保存到多个存储桶中



我正在尝试加载多个bucket,使用以下代码可以正常工作:

@Configuration
@EnableReactiveCouchbaseRepositories("com.abc.couchbase.repositories")
class ReactiveCouchbaseConfiguration extends AbstractCouchbaseConfiguration {
@Autowired
private CouchbaseProperties couchbaseProperties;
@Override
public String getConnectionString() {
return couchbaseProperties.getConnectionString();
}
@Override
public String getUserName() {
return couchbaseProperties.getUserName();
}
@Override
public String getPassword() {
return couchbaseProperties.getPassword();
}
@Override
public String getBucketName() {
return couchbaseProperties.getBucketName();
}
@Bean
protected ReactiveRepositoryOperationsMapping configureRepositoryOperationsMapping(ReactiveRepositoryOperationsMapping mapping) {
// only model that is mapped to custom template will be mapped to non-default bucket
return mapping.mapEntity(Layout.class, layoutTemplate());
}
@Bean
public ReactiveCouchbaseTemplate layoutTemplate() {
return customCouchbaseTemplate(customCouchbaseClientFactory("bucket2"));
}
public ReactiveCouchbaseTemplate customCouchbaseTemplate(CouchbaseClientFactory couchbaseClientFactory) {
return new ReactiveCouchbaseTemplate(couchbaseClientFactory, new MappingCouchbaseConverter());
}
public CouchbaseClientFactory customCouchbaseClientFactory(String bucketName) {
return new SimpleCouchbaseClientFactory(getConnectionString(), authenticator(), bucketName);
}
@Bean
public ReactiveCluster loadReactiveCluster() {
ClusterOptions clusterOptions = ClusterOptions.clusterOptions(couchbaseProperties.getUserName(), couchbaseProperties.getPassword());
return ReactiveCluster.connect(couchbaseProperties.getConnectionString(), clusterOptions);
}

但是在我的控制器中,如果我使用带有Layout实体的存储库以及其他bucket实体(即defult-bucket(,我会看到默认bucket只获取数据。上面配置的其他bucket布局从未获得数据。

@Autowired
private ReactiveCouchbaseRepository<Layout, String> layoutRepository;
@PostMapping("/service")
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<PageType> saveService(@RequestBody PageType pageType) {
Layout layout = new Layout();
layout.setLayoutId("dummy_101");
layout.setPageId("dummy_11");
repository.save(pageType).subscribe();
layoutRepository.save(layout).subscribe();
return new ResponseEntity<>(HttpStatus.OK);
}

请帮忙。我使用的是弹簧数据库4.3.3。

https://github.com/spring-projects/spring-data-couchbase/issues/878

@Bean受保护的ReactiveRepositoryOperationsMapping配置的RepositoryOperationsMappeng(ReactiveRepositoryOperations映射(

小心方法名称、签名和注释。使用@Override可确保您正在覆盖所需的方法。您应该覆盖的方法是

公共ReactiveRepositoryOperationsMapping ReactiveCouchbaseRepositoryOperationsMappeng(ReactiveCouchbaseTemplate ReactiveCouchbaseTemplate({

相关内容

  • 没有找到相关文章

最新更新