zoukankan      html  css  js  c++  java
  • Spring boot cassandra

    1.在Pom.xml添加spring-boot-starter-data-cassandra依赖:

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

    启动spring boot应用,出现错误:

    org.springframework.boot.SpringApplication: 815 - Application startup failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'session' defined in class path resource [org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.class]: 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))

    意思是说应用启动失败。是由于在CassandraDataAutoConfiguration类中创建bean时失败了。内部原因是应用启动过程中发现cassandra不可访问,抛出了NoHostAvailableException异常。

    默认情况下boot中的自动配置的Cassandra的host是127.0.0.1和0:0:0:0:0:0:0:1,两次尝试都失败了。

    =>在本地的C:WindowsSystem32driversetc目录中的hosts文件中添加:

    192.168.99.100 localhost

    将127.0.0.1映射到实际配置的ip,这里使用了在Docker中启用的Cassandra容器。

    =>spring boot提供了可以改配置的方式:

    在src/main/resources目录下添加application.properties文件,在其中添加:

    spring.data.cassandra.contact-points=192.168.99.100

    来修改配置信息。

  • 相关阅读:
    k8s 集群节点重启后etcd Unhealthy 解决
    no matches for kind “Deployment” in version "extensions/v1beta1 问题解决
    go web 读书笔记 (go 与 web 应用)
    Linux设置ssh超时时间
    C++中继承方式
    C++中类中范围解析运算符::和点运算符(.)
    C++ 中类与结构体的区别
    C++中. 与 -> 运算符的区别
    C++之字符串
    C++之数组
  • 原文地址:https://www.cnblogs.com/niaomingjian/p/6579612.html
Copyright © 2011-2022 走看看