我试图弄清楚如何使Spring与Couchbase一起工作但由于某种原因我得到以下异常:
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
连接很好,但由于某种原因无法创建bean.
这是我的spring-couchbase-integration.xml文件:
这是存储库:
package com.jcg.examples.repo;
...
@Repository
public interface BookRepo extends CouchbaseRepository
文件:
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;
}
}
这是我如何测试它:
package com.jcg.examples;
...
public class ApplicationTest {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new ClassPathResource("spring-couchbase-integration.xml").getPath());
}
}
这个例子取自this website.我已经设法解决了连接问题,因为我实际上并没有使用localhost,但是我无法弄清楚这一点.
编辑:问题已修复by configuring the Docker container properly因此修复了连接问题.
最佳答案
该消息表明SDK无法足够快地连接到群集.默认超时为5秒.
原文链接:https://www.f2er.com/spring/431352.htmlCouchbase Server是否已启动并在localhost上运行?如果您在实际配置中使用其他IP,客户端机器是否可以ping通它?有什么延迟?
您可以尝试设置更高的超时(以毫秒为单位):