Spring Couchbase查询总是超时?

时间:2017-03-17 13:31:08

标签: java spring spring-data-couchbase

spring-couchbase-integration.xml
================================
<?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>localhost</couchbase:node>
    </couchbase:cluster>

    <couchbase:clusterInfo login="athena" password="athena" />

    <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.paypal.risk.rims.batch.couchbase.repos" />

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

    <couchbase:bucket bucketName="baeldung"
        bucketPassword="" />

</beans:beans>

Book.java
=========
package com.jcg.examples.entity;

import org.springframework.data.couchbase.core.mapping.Document;

import com.couchbase.client.java.repository.annotation.Field;
import com.couchbase.client.java.repository.annotation.Id;

@Document(expiry = 0)
public class Book {

    @Id
    private long bookId;

    @Field
    private String name;

    @Field
    private long isbnNumber;

    public long getBookId() {
        return bookId;
    }

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

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public long getIsbnNumber() {
        return isbnNumber;
    }

    public void setIsbnNumber(long isbnNumber) {
        this.isbnNumber = isbnNumber;
    }

    @Override
    public String toString() {
        return "Book [bookId=" + bookId + ", name=" + name + ", isbnNumber=" + isbnNumber + "]";
    }

}

CouchBaseService.java
=====================
import java.util.List;

import javax.inject.Inject;

import org.springframework.data.couchbase.core.CouchbaseTemplate;
import org.springframework.data.couchbase.repository.query.support.N1qlUtils;
import org.springframework.stereotype.Service;

import com.couchbase.client.java.query.N1qlQuery;
import com.couchbase.client.java.query.Statement;
import com.couchbase.client.java.query.dsl.Expression;
import com.jcg.examples.entity.Book;

@Service
public class CouchBaseService {
    @Inject
    CouchbaseTemplate template;

    public void fetchDetailsFromCouchBase() {

        System.out.println("#############################################################################################");
        System.out.print("Book on FindById --->" + template.findById("333", Book.class));

        Statement statement = N1qlUtils.createSelectClauseForEntity(template.getCouchbaseBucket().name()).from(Expression.x(template.getCouchbaseBucket().name()))
                .where(Expression.x("name").eq("CouchBaseTutorial-->333"));
        N1qlQuery query = N1qlQuery.simple(statement);
        List<Book> result = template.findByN1QL(query, Book.class);
        System.out.print("Books on findByN1QL--->" + result);

        /*
         * Even the following does not work !!
         * 
         * N1qlQuery query1 = N1qlQuery.simple(
         * "SELECT * from baeldung where name=\"CouchBaseTutorial-->333\"");
         * N1qlQueryResult quertyResult = template.queryN1QL(query);
         * 
         */

    }

}

/ *     产量     ======     Book on FindById ---&gt; Book [bookId = 333,name = CouchBaseTutorial - &gt; 333,isbnNumber = 123789]     ...     ...     引起:java.lang.RuntimeException:java.util.concurrent.TimeoutException         在com.couchbase.client.java.util.Blocking.blockForSingle(Blocking.java:75)         在com.couchbase.client.java.CouchbaseBucket.query(CouchbaseBucket.java:638)         在com.couchbase.client.java.CouchbaseBucket.query(CouchbaseBucket.java:576)         在org.springframework.data.couchbase.core.CouchbaseTemplate $ 4.doInBucket(CouchbaseTemplate.java:450)         在org.springframework.data.couchbase.core.CouchbaseTemplate $ 4.doInBucket(CouchbaseTemplate.java:447)         在org.springframework.data.couchbase.core.CouchbaseTemplate.execute(CouchbaseTemplate.java:490)

* /

0 个答案:

没有答案