Connection with more than one bucket In JAVA SDK 3.0

Hi,

How can we connect more than one bucket in spring-boot application project using Java SDK 3.x.

see Connecting to multiple buckets on Couchbase cluster with Spring - Stack Overflow and Missing couchbase.repository.multibucket documentation (4.x) [DATACOUCH-570] · Issue #878 · spring-projects/spring-data-couchbase · GitHub

Hi @mreiche

Thanks for your reploy. After implementing the suggested logic I am getting some error.

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.couchbase.client.java.env.ClusterEnvironment]: Factory method ‘couchbaseClusterEnvironment’ threw exception; nested exception is java.lang.NullPointerException

During debug I found that line of code eventBus.get().start().block(); of CoreEnvironment.class is throwing NullPointerException.

Below is the stacktrace error:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.couchbase.client.java.env.ClusterEnvironment]: Factory method ‘couchbaseClusterEnvironment’ threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
… 75 common frames omitted
Caused by: java.lang.NullPointerException: null
at org.springframework.cloud.sleuth.instrument.reactor.ReactorSleuth.lambda$onLastOperatorForOnEachInstrumentation$4(ReactorSleuth.java:258)
at org.springframework.cloud.sleuth.instrument.reactor.ReactorHooksHelper$NamedLifter.apply(ReactorHooksHelper.java:222)
at reactor.core.publisher.MonoLift.subscribeOrReturn(MonoLift.java:41)
at reactor.core.publisher.Mono.subscribe(Mono.java:4385)
at reactor.core.publisher.Mono.block(Mono.java:1706)
at com.couchbase.client.core.env.CoreEnvironment.(CoreEnvironment.java:164)
at com.couchbase.client.java.env.ClusterEnvironment.(ClusterEnvironment.java:53)
at com.couchbase.client.java.env.ClusterEnvironment.(ClusterEnvironment.java:46)
at com.couchbase.client.java.env.ClusterEnvironment$Builder.build(ClusterEnvironment.java:213)
at org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration.couchbaseClusterEnvironment(AbstractCouchbaseConfiguration.java:145)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
… 76 common frames omitted
Suppressed: java.lang.Exception: #block terminated with an error
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:99)
at reactor.core.publisher.Mono.block(Mono.java:1707)
… 91 common frames omitted

The NPE is thrown at line 258 of ReactorSleuth - which is not a Couchbase class. Setting a break-point at that line might shed some light on the issue. Maybe the springContext is not initialized? Judging by the comment at line 257 - it seems like NPE is/was an issue at line 258.