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>
1条答案
按热度按时间lf5gs5x21#
我看到没有 * 阻塞 * 错误与您提供的代码。但正如上面提到的,这是你在POM中唯一需要的东西。
错误消息告诉我们主机
cassandra
没有被你的java代码解析。在注解中,您提供了
cqlsh
的输出,告诉我们数据库已启动并正在工作,但消息中给予了集群的**名称,而不是cassandra节点的主机。检查cqlsh输出与docker镜像的外观..显然Test Cluster
不是主机。几个想法:
ifconfig
显示IP/etc/config
添加条目