无法从springoot 3.1.1版本连接到cassandra 4.1.3版本

ukxgm1gy  于 2023-09-29  发布在  Spring
关注(0)|答案(1)|浏览(145)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cassandraSessionFactory' defined in class path resource [com/test/config/CassandraConfig.class]: Unsatisfied dependency expressed through method 'cassandraSessionFactory' parameter 0: Error creating bean with name 'cassandraSession' defined in class path resource [com/test/config/CassandraConfig.class]: Could not reach any contact point, make sure you've provided valid addresses (showing first 1 nodes, use getAllErrors() for more): Node(endPoint=cassandra/<unresolved>:9042, hostId=null, hashCode=65654666): [com.datastax.oss.driver.api.core.connection.ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (io.netty.channel.StacklessClosedChannelException)]
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800) ~[spring-beans-6.0.10.jar!/:6.0.10]
        at
@Bean
public CqlSessionFactoryBean cassandraSession() {
    CqlSessionFactoryBean session = new CqlSessionFactoryBean();
    session.setContactPoints("cassandra");
    session.setKeyspaceCreations(getKeyspaceCreations());
    session.setKeyspaceName(keySpace);
    session.setPort(port);
    session.setUsername(userName);
    session.setPassword(password);
    session.setLocalDatacenter(datacenter);
    session.setSessionBuilderConfigurer(sessionBuilder -> sessionBuilder
            .withConfigLoader(DriverConfigLoader
                    .programmaticBuilder()
                    .withString(DefaultDriverOption.REQUEST_TIMEOUT, "10 seconds")
                    .build()));
    return session;
}
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.1.1</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
<version>4.1.3</version>
</dependency>
lf5gs5x2

lf5gs5x21#

我看到没有 * 阻塞 * 错误与您提供的代码。但正如上面提到的,这是你在POM中唯一需要的东西。

<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-data-cassandra</artifactId>
 <version>3.1.3</version>
</dependency>

错误消息告诉我们主机cassandra没有被你的java代码解析。

Could not reach any contact point, make sure 
you've provided valid addresses (showing first 1 nodes, use getAllErrors() for more)

在注解中,您提供了cqlsh的输出,告诉我们数据库已启动并正在工作,但消息中给予了集群的**名称,而不是cassandra节点的主机。检查cqlsh输出与docker镜像的外观..显然Test Cluster不是主机。

Connected to Test Cluster at 127.0.0.1:9042
[cqlsh 6.0.0 | Cassandra 4.0.7-9cb79586cc78 | CQL spec 3.4.5 | Native protocol v5]
Use HELP for help.
cqlsh>

几个想法:

  • 将ssh连接到cassandra节点,并使用ifconfig显示IP
  • 通过正确的IP更改“cassandra”或向/etc/config添加条目

相关问题