Spring boot Spring引导和Couchbase连接错误
我开始一起学习SpringBoot和couchbase,并实现一个简单的自定义查询。然而,当我点击localhost:8889/agents/findByAgentId/14045时,我得到了“无法访问此站点”错误。我错过了什么?如有任何回应,我将不胜感激。多谢各位 这是实体类Spring boot Spring引导和Couchbase连接错误,spring-boot,couchbase,spring-data-couchbase,Spring Boot,Couchbase,Spring Data Couchbase,我开始一起学习SpringBoot和couchbase,并实现一个简单的自定义查询。然而,当我点击localhost:8889/agents/findByAgentId/14045时,我得到了“无法访问此站点”错误。我错过了什么?如有任何回应,我将不胜感激。多谢各位 这是实体类 import com.sun.istack.internal.NotNull; import lombok.*; import org.springframework.data.annotation.Id; import
import com.sun.istack.internal.NotNull;
import lombok.*;
import org.springframework.data.annotation.Id;
import org.springframework.data.couchbase.core.mapping.Document;
import org.springframework.data.couchbase.core.mapping.Field;
@Document
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
public class Agent {
@Id
@NotNull
@Field
private String AgentLeaderId;
@Field
private String agentPreference;
@Field
private String agency;
@Field
private String mobilePhone;
}
这是配置类
import org.springframework.context.annotation.Configuration;
import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
@Configuration
public class AgentConfig extends AbstractCouchbaseConfiguration {
@Override
public String getConnectionString() {
return ("127.0.0.1");
}
@Override
public String getUserName() {
return "******";
}
@Override
public String getPassword() {
return "*******";
}
@Override
public String getBucketName() {
return "******";
}
}
这是存储库
import com.bit.pruleads.entity.Agent;
import org.springframework.data.couchbase.core.query.N1qlPrimaryIndexed;
import org.springframework.data.couchbase.core.query.ViewIndexed;
import org.springframework.data.couchbase.repository.CouchbaseRepository;
import org.springframework.data.couchbase.repository.Query;
import org.springframework.stereotype.Repository;
import java.io.Serializable;
import java.util.List;
@Repository
@N1qlPrimaryIndexed
@ViewIndexed(designDoc = "primaryLeadsData")
public interface AgentRepository extends CouchbaseRepository<Agent, String > {
@Query("#{#n1ql.selectEntity} WHERE agentLeaderId = $1 AND #{#n1ql.filter}")
List<Agent> findByAgentId(String agentId);
@Query("#{#n1ql.selectEntity} WHERE mobilePhone = $1 AND #{#n1ql.filter}")
List<Agent> findAgentsByPhoneNumber(String phoneNumber);
}
这是一些日志
No active profile set, falling back to default profiles: default
Bootstrapping Spring Data Couchbase repositories in DEFAULT mode.
Finished Spring Data repository scanning in 456ms.
Found 0 Couchbase
repository interfaces.
Bootstrapping Spring Data Couchbase repositories in DEFAULT mode.
Finished Spring Data repository scanning in 35ms.
Found 1 Couchbase repository interfaces.
Opened bucket "leads-data"
Started PruleadsApplication in 7.502 seconds (JVM running for 8.685)
Closed bucket "leads-data"
Node disconnected
Completed shutdown and closed all open buckets
Process finished with exit code 0
首先,请改用此版本:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-couchbase</artifactId>
<version>4.1.1</version>
</dependency>
以下是一个例子:
https://github.com/deniswsrosa/spring-data-couchbase-quickstart
只需运行类“QuickStartCouchbase”,在应用程序启动后,应调用“CmdRunner”中的方法“Run”。我认为您需要在pom中包含
spring boot starter web
。在没有web服务器的情况下,spring boot启动后发现它没有任何作用,因此它将停止。感谢您的回复,我尝试了此解决方案,但没有成功。我假设问题与节点连接有关。Spring boot无法连接到couchbase服务器,但我不知道如何修复它。配置类是基于spring data couchbase文档配置的。@TunggulSagala这个应该可以工作。只需运行QuickStartCouchbase类,应用程序启动后应调用CmdRunner,它将运行一些演示方法谢谢您的响应,我不知道我必须包含此依赖项,现在我的应用程序已启动并运行,再次感谢您。但是,我这里还有另一个问题,它不公开任何端点,除了/actuator下面的所有端点。您能提供更多信息吗?是否有错误消息?您试图如何调用您的接口?很抱歉,现在它工作正常。似乎是eclipse缓存问题。重启后,一切正常。再次感谢你。
No active profile set, falling back to default profiles: default
Bootstrapping Spring Data Couchbase repositories in DEFAULT mode.
Finished Spring Data repository scanning in 456ms.
Found 0 Couchbase
repository interfaces.
Bootstrapping Spring Data Couchbase repositories in DEFAULT mode.
Finished Spring Data repository scanning in 35ms.
Found 1 Couchbase repository interfaces.
Opened bucket "leads-data"
Started PruleadsApplication in 7.502 seconds (JVM running for 8.685)
Closed bucket "leads-data"
Node disconnected
Completed shutdown and closed all open buckets
Process finished with exit code 0
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-couchbase</artifactId>
<version>4.1.1</version>
</dependency>
CREATE PRIMARY INDEX ON MY_BUCKET
https://github.com/deniswsrosa/spring-data-couchbase-quickstart