Hi,
I am trying to connect to two different buckets inside same couchbase cluster.
Spring data configures the default one itself.
I have overridden all required methods in my custom bucket and mapped the repoistory to be used as well with the custom couchbase template.
@Bean(name = "coucbaseMappingConverter")
public MappingCouchbaseConverter mappingCustomCouchbaseConverter() throws Exception {
MappingCouchbaseConverter converter =
new CustomMappingCouchbaseConverter(couchbaseMappingContext());
converter.setCustomConversions(customConversions());
return converter;
}
@Bean(name = "customBucket")
public Bucket customBucket() throws Exception {
return couchbaseConfigurer()
.couchbaseCluster()
.openBucket("replicaBucket");
}
@Bean("customCouchbaseTemplate")
public CouchbaseTemplate customCouchbaseTemplate() throws Exception {
CouchbaseTemplate template =
new CouchbaseTemplate(
couchbaseClusterInfo(), customBucket(),
mappingCustomCouchbaseConverter(), translationService());
template.setDefaultConsistency(getDefaultConsistency());
return template;
}
@SneakyThrows
@Bean("publishRepositoryOperationMapping")
public RepositoryOperationsMapping publishRepositoryOperationMapping(){
RepositoryOperationsMapping baseMapping = new RepositoryOperationsMapping(customCouchbaseTemplate());
configureRepositoryOperationsMapping(baseMapping);
return baseMapping;
}
@Override
@SneakyThrows
public void configureRepositoryOperationsMapping(RepositoryOperationsMapping publishRepositoryOperationMapping) {
publishRepositoryOperationMapping.mapEntity(CustomRepository.class, customCouchbaseTemplate());
}
Now In my repoistory for this custom bucket. I have the niql way to get the bucket name , #{#n1ql bucket} … this always gives me the default bucket name.
CustomRepository Interface
@Query(Select * from #{#n1ql bucket})
Optional getResponse();
in logs I can see the bucket name that gets replaced by #{#n1ql bucket} is the default bucket name and not my custom name.
Is there some more configuration required which i am missing