gpt4 book ai didi

java - "Error creating bean with name"沙发底座 + Spring

转载 作者:搜寻专家 更新时间:2023-10-31 20:17:53 24 4
gpt4 key购买 nike

我正在尝试弄清楚如何让 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 文件:

<?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>

这是存储库:

package com.jcg.examples.repo;

...

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

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

文档:

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 秒。

Couchbase 服务器是否在 localhost 上启动并运行?如果您在实际配置中使用另一个 IP,客户端机器可以 ping 通它吗?有多少延迟?

您可以尝试设置更高的超时时间(以毫秒为单位):

<couchbase:env id="couchbaseEnv" connectTimeout="10000" />

关于java - "Error creating bean with name"沙发底座 + Spring ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37847006/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com