无法连接到停靠的cassandra

xzlaal3s  于 2021-06-15  发布在  Cassandra
关注(0)|答案(1)|浏览(403)

代码引发以下异常:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraConfiguration': Invocation of init method failed; nested exception is 

 com.datastax.driver.core.exceptions.NoHostAvailableException:
 All host(s) tried for query failed
 (
   tried:

   localhost/127.0.0.1:9042
   (com.datastax.driver.core.exceptions.TransportException: [localhost/127.0.0.1:9042]
    Cannot connect),

   localhost/0:0:0:0:0:0:0:1:9042
   (com.datastax.driver.core.exceptions.TransportException: [localhost/0:0:0:0:0:0:0:1:9042]
    Cannot connect)
 )

我使用的是github上的jhipster示例。跑步 mvnw clean test 不返回任何失败。
端口9042和9160已在防火墙中打开。
依赖项是cassandra驱动程序附加项、cassandra驱动程序Map和spring boot starter数据cassandra。

zengzsys

zengzsys1#

这是application-dev.yml的重要部分:

spring:
    data:
        cassandra:
            contactPoints: localhost
            protocolVersion: V4
            compression: LZ4
            keyspaceName: demo_ks
            entityPackage: com.demo.domain
            port: 9042

必须使用一个docker compose文件来启动容器 cassandra:3.11.3 ,端口9042、9160、7199、7000、7001和卷 cassandra_data:/data . 稍后,我将把它放在某个github存储库中,并用完整的代码编辑这个答案。
我的 CassandraConfiguration 班上有豆子回来了 CassandraCustomConversions , ClusterBuilderCustomizer 以及 Session ,也是自动连线的 Cluster 以及 MetricRegistry .
重要章节 pom.xml :

<properties>
    <spring-boot.version>2.0.5.RELEASE</spring-boot.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.cassandraunit</groupId>
        <artifactId>cassandra-unit-spring</artifactId>
        <scope>test</scope>
    </dependency>

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

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-cassandra</artifactId>
    </dependency>

    <dependency>
        <groupId>com.datastax.cassandra</groupId>
        <artifactId>cassandra-driver-extras</artifactId>
    </dependency>

    <dependency>
        <groupId>com.datastax.cassandra</groupId>
        <artifactId>cassandra-driver-mapping</artifactId>
    </dependency>
</dependencies>

相关问题