Spring boot cassandra - nested exception is com.datastax.driver.core.exceptions.NoHostAvailableException
2017-03-19 10:37
1736 查看
1.在Pom.xml添加spring-boot-starter-data-cassandra依赖:
启动spring boot应用,出现错误:
意思是说应用启动失败。是由于在CassandraDataAutoConfiguration类中创建bean时失败了。内部原因是应用启动过程中发现cassandra不可访问,抛出了NoHostAvailableException异常。
默认情况下boot中的自动配置的Cassandra的host是127.0.0.1和0:0:0:0:0:0:0:1,两次尝试都失败了。
=>在本地的C:\Windows\System32\drivers\etc目录中的hosts文件中添加:
将127.0.0.1映射到实际配置的ip,这里使用了在Docker中启用的Cassandra容器。
=>spring boot提供了可以改配置的方式:
在src/main/resources目录下添加application.properties文件,在其中添加:
来修改配置信息。
<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:\Windows\System32\drivers\etc目录中的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
来修改配置信息。
相关文章推荐
- spring No default constructor found; nested exception is java.lang.NoSuchMethodException: com.slj.mo
- nested exception is java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonGenerator.writeStart
- nested exception is java.lang.IncompatibleClassChangeError: class org.springframework.core.type.clas
- org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.Persiste
- nested exception is org.springframework.core.NestedIOException: ASM ClassReader failed to parse cla
- nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/util/DefaultIndenter
- 2016.11.10 Could not get JDBC Connection; nested exception is java.sql.SQLException: No suitable driver
- ibatis+spring+mysql nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
- Cannot deserialize; nested exception is org.springframework.core.serializer.support.SerializationFai
- FAQ(39):org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.
- No transactional EntityManager available; nested exception is javax.persistence.TransactionRequiredException: No transactional EntityManager available
- springmvc项目启动报错 nested exception is org.springframework.core.NestedIOException
- org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.Persiste
- nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/util/DefaultIndenter
- 关于dubbo调度时出现Request processing failed; nested exception is com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method insertTestTb in the service cn.cuibusi.core.service.TestTbService.的解决办法
- nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/util/DefaultIndenter
- Spring Cloud ZooKeeper集成Feign的坑2,服务调用了一次后第二次调用就变成了500,错误:Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.n
- org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'username' not found. Available parameters are [1, 0, param1, param2]
- nested exception is java.sql.SQLException: com.mysql.jdbc.Driver
- nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException