Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Error creating bean with name" Couchbase + Spring

I'm trying to figure out how to get Spring to work with Couchbase but for some reason I'm getting the following exception:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookRepo': Cannot resolve reference to bean 'couchbaseTemplate' while setting bean property 'couchbaseOperations'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'couchbaseTemplate': Cannot resolve reference to bean 'couchbaseBucket' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'couchbaseBucket': Invocation of init method failed; nested exception is java.lang.RuntimeException: java.util.concurrent.TimeoutException

The connection is fine but for some reason the beans cannot be created.

Here's my spring-couchbase-integration.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:couchbase="http://www.springframework.org/schema/data/couchbase"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
    http://www.springframework.org/schema/data/couchbase
    http://www.springframework.org/schema/data/couchbase/spring-couchbase.xsd">

    <couchbase:cluster>
        <couchbase:node>127.0.0.1</couchbase:node>
    </couchbase:cluster>

    <!-- This is needed to probe the server for N1QL support -->
    <!-- Can be either cluster credentials or a bucket credentials -->
    <couchbase:clusterInfo login="login"
        password="password" />

    <beans:bean id="couchbaseEnv"
        class="com.couchbase.client.java.env.DefaultCouchbaseEnvironment"
        factory-method="create" />
    <beans:bean id="myCustomTranslationService"
        class="org.springframework.data.couchbase.core.convert.translation.JacksonTranslationService" />

    <couchbase:indexManager />

    <couchbase:repositories base-package="com.jcg.examples.repo" />

    <couchbase:template translation-service-ref="myCustomTranslationService" />

    <couchbase:bucket bucketName="JavaCodeGeeks"
        bucketPassword="password.1" />
</beans:beans>

Here's the repository:

package com.jcg.examples.repo;

...

@Repository
public interface BookRepo extends CouchbaseRepository<Book, Long> {

    @Query(value = "select * from JavaCodeGeeks")
    public List<Book> getBooksByContainedWord(String containedString);
}

The document:

package com.jcg.examples.entity;

...

@Document(expiry = 0)
public class Book {

    @Id
    private long bookId;

    public long getBookId() {
        return bookId;
    }

    public void setBookId(long bookId) {
            this.bookId = bookId;
    }

}

And a here's how I'm testing it:

package com.jcg.examples;

...

public class ApplicationTest {

    public static void main(String[] args) {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new ClassPathResource("spring-couchbase-integration.xml").getPath());
    }
}

The example is taken from this website. I've managed to fix the connection issues since I'm not actually using localhost but I haven't been able to figure this one out.

EDIT: The problem was fixed by configuring the Docker container properly thus fixing the connection issues.

like image 770
tomtomssi Avatar asked Jun 15 '16 22:06

tomtomssi


1 Answers

The message indicates that the SDK couldn't connect to the cluster quickly enough. The default timeout is 5 seconds.

Is Couchbase Server up and running on localhost? If you are using another IP in your actual config, can the client machine ping to it? With what latency?

You can try setting a higher timeout (in milliseconds):

<couchbase:env id="couchbaseEnv" connectTimeout="10000" />
like image 101
Simon Baslé Avatar answered Sep 29 '22 04:09

Simon Baslé