spring boot cant connect to cassandra database









up vote
0
down vote

favorite












i am using a spring boot quick start and want to establish a connection to a cassandra instance that is running on an ubuntu VM on the same machine,
i get this error when running the spring boot app



 . ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _
( ( )___ | '_ | '_| | '_ / _` |
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |___, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.5.RELEASE)

2018-11-08 18:00:10.671 INFO 12076 --- [ main] hello.Application : Starting Application on DESKTOP-OG0KPA1 with PID 12076 (C:Usersomar_Downloadsgs-spring-boot-mastergs-spring-boot-mastercompletetargetclasses started by omar_ in C:Usersomar_Downloadsgs-spring-boot-mastergs-spring-boot-mastercomplete)
2018-11-08 18:00:10.680 INFO 12076 --- [ main] hello.Application : No active profile set, falling back to default profiles: default
2018-11-08 18:00:10.966 INFO 12076 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@60dcc9fe: startup date [Thu Nov 08 18:00:10 EET 2018]; root of context hierarchy
2018-11-08 18:00:12.701 INFO 12076 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'cassandraTemplate' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=cassandraConfig; factoryMethodName=cassandraTemplate; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [hello/CassandraConfig.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration; factoryMethodName=cassandraTemplate; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.class]]
2018-11-08 18:00:13.020 INFO 12076 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2018-11-08 18:00:13.112 INFO 12076 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2018-11-08 18:00:14.517 INFO 12076 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8087 (http)
2018-11-08 18:00:14.560 INFO 12076 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-11-08 18:00:14.561 INFO 12076 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.34
2018-11-08 18:00:14.570 INFO 12076 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:Program FilesJavajdk1.8.0_121bin;C:WINDOWSSunJavabin;C:WINDOWSsystem32;C:WINDOWS;C:Program FilesDellDW WLAN Card;C:ProgramDataOracleJavajavapath;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:Program Files (x86)Bracketscommand;C:Program Files (x86)GtkSharp2.12bin;C:Program Files (x86)Gitcmd;C:Program Filesnodejs;C:PostgreSQLpg10bin;C:Program FilesPuTTY;C:WINDOWSSystem32OpenSSH;D:PostgreSQLpg10bin;C:Usersomar_Downloadsapache-maven-3.5.4-binapache-maven-3.5.4bin;C:Usersomar_AppDataLocalatombin;C:Usersomar_AppDataLocalMicrosoftWindowsApps;C:Usersomar_AppDataRoamingnpm;C:Program FilesMicrosoft VS Codebin;C:Usersomar_Downloadsapache-cassandra-3.11.3-binapache-cassandra-3.11.3bin;C:Python27;;.]
2018-11-08 18:00:14.775 INFO 12076 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-11-08 18:00:14.775 INFO 12076 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3830 ms
2018-11-08 18:00:15.491 ERROR 12076 --- [ost-startStop-1] o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthEndpoint]: Factory method 'healthEndpoint' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthIndicatorAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cluster' defined in class path resource [hello/CassandraConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.cassandra.config.CassandraClusterFactoryBean]: Factory method 'cluster' threw exception; nested exception is java.lang.NumberFormatException: null
2018-11-08 18:00:15.522 INFO 12076 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-11-08 18:00:15.534 WARN 12076 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2018-11-08 18:00:15.560 INFO 12076 --- [ main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-11-08 18:00:15.583 ERROR 12076 --- [ main] o.s.boot.SpringApplication : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1277) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1265) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at hello.Application.main(Application.java:15) [classes/:na]
Caused by: java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:542) ~[na:1.8.0_121]
at java.lang.Integer.parseInt(Integer.java:615) ~[na:1.8.0_121]
at hello.CassandraConfig.cluster(CassandraConfig.java:32) ~[classes/:na]
at hello.CassandraConfig$$EnhancerBySpringCGLIB$$bf5637d0.CGLIB$cluster$0(<generated>) ~[classes/:na]
at hello.CassandraConfig$$EnhancerBySpringCGLIB$$bf5637d0$$FastClassBySpringCGLIB$$bfd61920.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:365) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at hello.CassandraConfig$$EnhancerBySpringCGLIB$$bf5637d0.cluster(<generated>) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
... 122 common frames omitted


Process finished with exit code 1


here is my pom.xml:



<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.springframework</groupId>
<artifactId>gs-spring-boot</artifactId>
<version>0.1.0</version>



<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- tag::actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- end::actuator -->
<!-- tag::tests -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

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


<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-opengis</artifactId>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-data</artifactId>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-epsg-hsql</artifactId>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-wfs-ng</artifactId>
<version>$gt.version</version>
</dependency>

<!--<dependency>-->
<!--<groupId>org.apache.cassandra</groupId>-->
<!--<artifactId>cassandra-all</artifactId>-->
<!--<version>3.11.3</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.datastax.cassandra</groupId>-->
<!--<artifactId>cassandra-driver-core</artifactId>-->
<!--<version>3.6.0</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.springframework.data</groupId>-->
<!--<artifactId>spring-data-cassandra</artifactId>-->
<!--</dependency>-->

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


<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>


<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.6.0</version>
</dependency>

<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>



<!--<dependency>-->
<!--<groupId>org.cassandraunit</groupId>-->
<!--<artifactId>cassandra-unit-spring</artifactId>-->
<!--<version>$cassandra-unit-spring.version</version>-->
<!--<scope>test</scope>-->
<!--<exclusions>-->
<!--<exclusion>-->
<!--<groupId>org.cassandraunit</groupId>-->
<!--<artifactId>cassandra-unit</artifactId>-->
<!--</exclusion>-->
<!--</exclusions>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.cassandraunit</groupId>-->
<!--<artifactId>cassandra-unit-shaded</artifactId>-->
<!--<version>$cassandra-unit-shaded.version</version>-->
<!--<scope>test</scope>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.hectorclient</groupId>-->
<!--<artifactId>hector-core</artifactId>-->
<!--<version>$hector-core.version</version>-->
<!--<exclusions>-->
<!--<exclusion>-->
<!--<artifactId>commons-logging</artifactId>-->
<!--<groupId>commons-logging</groupId>-->
<!--</exclusion>-->
<!--</exclusions>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.datastax.cassandra</groupId>-->
<!--<artifactId>cassandra-driver-core</artifactId>-->
<!--<version>$cassandra-driver-core.version</version>-->
<!--<optional>true</optional>-->
<!--</dependency>-->
<!-- end::tests -->
</dependencies>

<properties>
<java.version>1.8</java.version>
<cassandra-driver-core.version>3.6.0</cassandra-driver-core.version>
<cassandra-unit-spring.version>2.1.9.2</cassandra-unit-spring.version>
<cassandra-unit-shaded.version>2.1.9.2</cassandra-unit-shaded.version>
<hector-core.version>2.0-0</hector-core.version>
<guava.version>19.0</guava.version>
<gt.version>18.0</gt.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>







</plugins>
</build>


<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>


<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

</project>


i have set up a cassandra.properties file setting the host and port and keyspacename, also there is a cassandra config java class that sets the connection parameters to connect to the cluster
here is the file:



package hello;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.data.cassandra.config.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.config.CassandraClusterFactoryBean;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;


@Configuration
public class CassandraConfig extends AbstractCassandraConfiguration
private static final Log LOGGER = LogFactory.getLog(CassandraConfig.class);

@Autowired
private Environment environment;

@Override
protected String getKeyspaceName()
return environment.getProperty("spring.data.cassandra.keyspace-name");


@Override
@Bean
public CassandraClusterFactoryBean cluster()
final CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
cluster.setContactPoints(environment.getProperty("spring.data.cassandra.contact-points"));
cluster.setPort(Integer.parseInt(environment.getProperty("spring.data.cassandra.port")));
LOGGER.info("Cluster created with contact points [" + environment.getProperty("spring.data.cassandra.contact-points") + "] " + "& port [" + Integer.parseInt(environment.getProperty("spring.data.cassandra.port")) + "].");
return cluster;


//
// @Bean
// public CassandraClusterFactoryBean cluster()
// CassandraClusterFactoryBean cluster =
// new CassandraClusterFactoryBean();
// cluster.setContactPoints("192.168.164.130");
// cluster.setPort(9042);
// return cluster;
//

@Override
@Bean
public CassandraMappingContext cassandraMapping() throws ClassNotFoundException
return new BasicCassandraMappingContext();


// @Bean
// public CassandraMappingContext cassandraMapping()
// throws ClassNotFoundException
// return new BasicCassandraMappingContext();
//



what else am i missing ?



EDIT : it turned out that i had to change the rpc_address in the cassandra.yml file in the vm host from localhost to the vm ip address, so its exposed to external connections










share|improve this question



















  • 1




    From the obvious in your post, the problem is caused by this line: cluster.setPort(Integer.parseInt(environment.getProperty("spring.data.cassandra.port")));. And that can be the case only if environment.getProperty("spring.data.cassandra.port") returns null. Just make sure that your port config entry is properly configured and accessible.
    – ernest_k
    Nov 8 at 17:18










  • github.com/girdhar-singh-rathore/…
    – Girdhar Singh Rathore
    Nov 8 at 19:27










  • still gives the same error : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerController': Unsatisfied dependency expressed through field 'customerService';
    – omarshiha
    Nov 8 at 20:33










  • Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /192.168.164.130:9042 (com.datastax.driver.core.exceptions.TransportException: [/192.168.164.130:9042] Cannot connect))
    – omarshiha
    Nov 8 at 20:33














up vote
0
down vote

favorite












i am using a spring boot quick start and want to establish a connection to a cassandra instance that is running on an ubuntu VM on the same machine,
i get this error when running the spring boot app



 . ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _
( ( )___ | '_ | '_| | '_ / _` |
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |___, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.5.RELEASE)

2018-11-08 18:00:10.671 INFO 12076 --- [ main] hello.Application : Starting Application on DESKTOP-OG0KPA1 with PID 12076 (C:Usersomar_Downloadsgs-spring-boot-mastergs-spring-boot-mastercompletetargetclasses started by omar_ in C:Usersomar_Downloadsgs-spring-boot-mastergs-spring-boot-mastercomplete)
2018-11-08 18:00:10.680 INFO 12076 --- [ main] hello.Application : No active profile set, falling back to default profiles: default
2018-11-08 18:00:10.966 INFO 12076 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@60dcc9fe: startup date [Thu Nov 08 18:00:10 EET 2018]; root of context hierarchy
2018-11-08 18:00:12.701 INFO 12076 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'cassandraTemplate' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=cassandraConfig; factoryMethodName=cassandraTemplate; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [hello/CassandraConfig.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration; factoryMethodName=cassandraTemplate; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.class]]
2018-11-08 18:00:13.020 INFO 12076 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2018-11-08 18:00:13.112 INFO 12076 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2018-11-08 18:00:14.517 INFO 12076 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8087 (http)
2018-11-08 18:00:14.560 INFO 12076 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-11-08 18:00:14.561 INFO 12076 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.34
2018-11-08 18:00:14.570 INFO 12076 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:Program FilesJavajdk1.8.0_121bin;C:WINDOWSSunJavabin;C:WINDOWSsystem32;C:WINDOWS;C:Program FilesDellDW WLAN Card;C:ProgramDataOracleJavajavapath;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:Program Files (x86)Bracketscommand;C:Program Files (x86)GtkSharp2.12bin;C:Program Files (x86)Gitcmd;C:Program Filesnodejs;C:PostgreSQLpg10bin;C:Program FilesPuTTY;C:WINDOWSSystem32OpenSSH;D:PostgreSQLpg10bin;C:Usersomar_Downloadsapache-maven-3.5.4-binapache-maven-3.5.4bin;C:Usersomar_AppDataLocalatombin;C:Usersomar_AppDataLocalMicrosoftWindowsApps;C:Usersomar_AppDataRoamingnpm;C:Program FilesMicrosoft VS Codebin;C:Usersomar_Downloadsapache-cassandra-3.11.3-binapache-cassandra-3.11.3bin;C:Python27;;.]
2018-11-08 18:00:14.775 INFO 12076 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-11-08 18:00:14.775 INFO 12076 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3830 ms
2018-11-08 18:00:15.491 ERROR 12076 --- [ost-startStop-1] o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthEndpoint]: Factory method 'healthEndpoint' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthIndicatorAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cluster' defined in class path resource [hello/CassandraConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.cassandra.config.CassandraClusterFactoryBean]: Factory method 'cluster' threw exception; nested exception is java.lang.NumberFormatException: null
2018-11-08 18:00:15.522 INFO 12076 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-11-08 18:00:15.534 WARN 12076 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2018-11-08 18:00:15.560 INFO 12076 --- [ main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-11-08 18:00:15.583 ERROR 12076 --- [ main] o.s.boot.SpringApplication : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1277) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1265) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at hello.Application.main(Application.java:15) [classes/:na]
Caused by: java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:542) ~[na:1.8.0_121]
at java.lang.Integer.parseInt(Integer.java:615) ~[na:1.8.0_121]
at hello.CassandraConfig.cluster(CassandraConfig.java:32) ~[classes/:na]
at hello.CassandraConfig$$EnhancerBySpringCGLIB$$bf5637d0.CGLIB$cluster$0(<generated>) ~[classes/:na]
at hello.CassandraConfig$$EnhancerBySpringCGLIB$$bf5637d0$$FastClassBySpringCGLIB$$bfd61920.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:365) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at hello.CassandraConfig$$EnhancerBySpringCGLIB$$bf5637d0.cluster(<generated>) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
... 122 common frames omitted


Process finished with exit code 1


here is my pom.xml:



<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.springframework</groupId>
<artifactId>gs-spring-boot</artifactId>
<version>0.1.0</version>



<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- tag::actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- end::actuator -->
<!-- tag::tests -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

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


<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-opengis</artifactId>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-data</artifactId>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-epsg-hsql</artifactId>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-wfs-ng</artifactId>
<version>$gt.version</version>
</dependency>

<!--<dependency>-->
<!--<groupId>org.apache.cassandra</groupId>-->
<!--<artifactId>cassandra-all</artifactId>-->
<!--<version>3.11.3</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.datastax.cassandra</groupId>-->
<!--<artifactId>cassandra-driver-core</artifactId>-->
<!--<version>3.6.0</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.springframework.data</groupId>-->
<!--<artifactId>spring-data-cassandra</artifactId>-->
<!--</dependency>-->

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


<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>


<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.6.0</version>
</dependency>

<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>



<!--<dependency>-->
<!--<groupId>org.cassandraunit</groupId>-->
<!--<artifactId>cassandra-unit-spring</artifactId>-->
<!--<version>$cassandra-unit-spring.version</version>-->
<!--<scope>test</scope>-->
<!--<exclusions>-->
<!--<exclusion>-->
<!--<groupId>org.cassandraunit</groupId>-->
<!--<artifactId>cassandra-unit</artifactId>-->
<!--</exclusion>-->
<!--</exclusions>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.cassandraunit</groupId>-->
<!--<artifactId>cassandra-unit-shaded</artifactId>-->
<!--<version>$cassandra-unit-shaded.version</version>-->
<!--<scope>test</scope>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.hectorclient</groupId>-->
<!--<artifactId>hector-core</artifactId>-->
<!--<version>$hector-core.version</version>-->
<!--<exclusions>-->
<!--<exclusion>-->
<!--<artifactId>commons-logging</artifactId>-->
<!--<groupId>commons-logging</groupId>-->
<!--</exclusion>-->
<!--</exclusions>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.datastax.cassandra</groupId>-->
<!--<artifactId>cassandra-driver-core</artifactId>-->
<!--<version>$cassandra-driver-core.version</version>-->
<!--<optional>true</optional>-->
<!--</dependency>-->
<!-- end::tests -->
</dependencies>

<properties>
<java.version>1.8</java.version>
<cassandra-driver-core.version>3.6.0</cassandra-driver-core.version>
<cassandra-unit-spring.version>2.1.9.2</cassandra-unit-spring.version>
<cassandra-unit-shaded.version>2.1.9.2</cassandra-unit-shaded.version>
<hector-core.version>2.0-0</hector-core.version>
<guava.version>19.0</guava.version>
<gt.version>18.0</gt.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>







</plugins>
</build>


<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>


<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

</project>


i have set up a cassandra.properties file setting the host and port and keyspacename, also there is a cassandra config java class that sets the connection parameters to connect to the cluster
here is the file:



package hello;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.data.cassandra.config.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.config.CassandraClusterFactoryBean;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;


@Configuration
public class CassandraConfig extends AbstractCassandraConfiguration
private static final Log LOGGER = LogFactory.getLog(CassandraConfig.class);

@Autowired
private Environment environment;

@Override
protected String getKeyspaceName()
return environment.getProperty("spring.data.cassandra.keyspace-name");


@Override
@Bean
public CassandraClusterFactoryBean cluster()
final CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
cluster.setContactPoints(environment.getProperty("spring.data.cassandra.contact-points"));
cluster.setPort(Integer.parseInt(environment.getProperty("spring.data.cassandra.port")));
LOGGER.info("Cluster created with contact points [" + environment.getProperty("spring.data.cassandra.contact-points") + "] " + "& port [" + Integer.parseInt(environment.getProperty("spring.data.cassandra.port")) + "].");
return cluster;


//
// @Bean
// public CassandraClusterFactoryBean cluster()
// CassandraClusterFactoryBean cluster =
// new CassandraClusterFactoryBean();
// cluster.setContactPoints("192.168.164.130");
// cluster.setPort(9042);
// return cluster;
//

@Override
@Bean
public CassandraMappingContext cassandraMapping() throws ClassNotFoundException
return new BasicCassandraMappingContext();


// @Bean
// public CassandraMappingContext cassandraMapping()
// throws ClassNotFoundException
// return new BasicCassandraMappingContext();
//



what else am i missing ?



EDIT : it turned out that i had to change the rpc_address in the cassandra.yml file in the vm host from localhost to the vm ip address, so its exposed to external connections










share|improve this question



















  • 1




    From the obvious in your post, the problem is caused by this line: cluster.setPort(Integer.parseInt(environment.getProperty("spring.data.cassandra.port")));. And that can be the case only if environment.getProperty("spring.data.cassandra.port") returns null. Just make sure that your port config entry is properly configured and accessible.
    – ernest_k
    Nov 8 at 17:18










  • github.com/girdhar-singh-rathore/…
    – Girdhar Singh Rathore
    Nov 8 at 19:27










  • still gives the same error : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerController': Unsatisfied dependency expressed through field 'customerService';
    – omarshiha
    Nov 8 at 20:33










  • Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /192.168.164.130:9042 (com.datastax.driver.core.exceptions.TransportException: [/192.168.164.130:9042] Cannot connect))
    – omarshiha
    Nov 8 at 20:33












up vote
0
down vote

favorite









up vote
0
down vote

favorite











i am using a spring boot quick start and want to establish a connection to a cassandra instance that is running on an ubuntu VM on the same machine,
i get this error when running the spring boot app



 . ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _
( ( )___ | '_ | '_| | '_ / _` |
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |___, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.5.RELEASE)

2018-11-08 18:00:10.671 INFO 12076 --- [ main] hello.Application : Starting Application on DESKTOP-OG0KPA1 with PID 12076 (C:Usersomar_Downloadsgs-spring-boot-mastergs-spring-boot-mastercompletetargetclasses started by omar_ in C:Usersomar_Downloadsgs-spring-boot-mastergs-spring-boot-mastercomplete)
2018-11-08 18:00:10.680 INFO 12076 --- [ main] hello.Application : No active profile set, falling back to default profiles: default
2018-11-08 18:00:10.966 INFO 12076 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@60dcc9fe: startup date [Thu Nov 08 18:00:10 EET 2018]; root of context hierarchy
2018-11-08 18:00:12.701 INFO 12076 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'cassandraTemplate' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=cassandraConfig; factoryMethodName=cassandraTemplate; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [hello/CassandraConfig.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration; factoryMethodName=cassandraTemplate; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.class]]
2018-11-08 18:00:13.020 INFO 12076 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2018-11-08 18:00:13.112 INFO 12076 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2018-11-08 18:00:14.517 INFO 12076 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8087 (http)
2018-11-08 18:00:14.560 INFO 12076 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-11-08 18:00:14.561 INFO 12076 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.34
2018-11-08 18:00:14.570 INFO 12076 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:Program FilesJavajdk1.8.0_121bin;C:WINDOWSSunJavabin;C:WINDOWSsystem32;C:WINDOWS;C:Program FilesDellDW WLAN Card;C:ProgramDataOracleJavajavapath;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:Program Files (x86)Bracketscommand;C:Program Files (x86)GtkSharp2.12bin;C:Program Files (x86)Gitcmd;C:Program Filesnodejs;C:PostgreSQLpg10bin;C:Program FilesPuTTY;C:WINDOWSSystem32OpenSSH;D:PostgreSQLpg10bin;C:Usersomar_Downloadsapache-maven-3.5.4-binapache-maven-3.5.4bin;C:Usersomar_AppDataLocalatombin;C:Usersomar_AppDataLocalMicrosoftWindowsApps;C:Usersomar_AppDataRoamingnpm;C:Program FilesMicrosoft VS Codebin;C:Usersomar_Downloadsapache-cassandra-3.11.3-binapache-cassandra-3.11.3bin;C:Python27;;.]
2018-11-08 18:00:14.775 INFO 12076 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-11-08 18:00:14.775 INFO 12076 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3830 ms
2018-11-08 18:00:15.491 ERROR 12076 --- [ost-startStop-1] o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthEndpoint]: Factory method 'healthEndpoint' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthIndicatorAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cluster' defined in class path resource [hello/CassandraConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.cassandra.config.CassandraClusterFactoryBean]: Factory method 'cluster' threw exception; nested exception is java.lang.NumberFormatException: null
2018-11-08 18:00:15.522 INFO 12076 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-11-08 18:00:15.534 WARN 12076 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2018-11-08 18:00:15.560 INFO 12076 --- [ main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-11-08 18:00:15.583 ERROR 12076 --- [ main] o.s.boot.SpringApplication : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1277) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1265) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at hello.Application.main(Application.java:15) [classes/:na]
Caused by: java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:542) ~[na:1.8.0_121]
at java.lang.Integer.parseInt(Integer.java:615) ~[na:1.8.0_121]
at hello.CassandraConfig.cluster(CassandraConfig.java:32) ~[classes/:na]
at hello.CassandraConfig$$EnhancerBySpringCGLIB$$bf5637d0.CGLIB$cluster$0(<generated>) ~[classes/:na]
at hello.CassandraConfig$$EnhancerBySpringCGLIB$$bf5637d0$$FastClassBySpringCGLIB$$bfd61920.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:365) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at hello.CassandraConfig$$EnhancerBySpringCGLIB$$bf5637d0.cluster(<generated>) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
... 122 common frames omitted


Process finished with exit code 1


here is my pom.xml:



<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.springframework</groupId>
<artifactId>gs-spring-boot</artifactId>
<version>0.1.0</version>



<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- tag::actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- end::actuator -->
<!-- tag::tests -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

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


<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-opengis</artifactId>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-data</artifactId>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-epsg-hsql</artifactId>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-wfs-ng</artifactId>
<version>$gt.version</version>
</dependency>

<!--<dependency>-->
<!--<groupId>org.apache.cassandra</groupId>-->
<!--<artifactId>cassandra-all</artifactId>-->
<!--<version>3.11.3</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.datastax.cassandra</groupId>-->
<!--<artifactId>cassandra-driver-core</artifactId>-->
<!--<version>3.6.0</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.springframework.data</groupId>-->
<!--<artifactId>spring-data-cassandra</artifactId>-->
<!--</dependency>-->

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


<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>


<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.6.0</version>
</dependency>

<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>



<!--<dependency>-->
<!--<groupId>org.cassandraunit</groupId>-->
<!--<artifactId>cassandra-unit-spring</artifactId>-->
<!--<version>$cassandra-unit-spring.version</version>-->
<!--<scope>test</scope>-->
<!--<exclusions>-->
<!--<exclusion>-->
<!--<groupId>org.cassandraunit</groupId>-->
<!--<artifactId>cassandra-unit</artifactId>-->
<!--</exclusion>-->
<!--</exclusions>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.cassandraunit</groupId>-->
<!--<artifactId>cassandra-unit-shaded</artifactId>-->
<!--<version>$cassandra-unit-shaded.version</version>-->
<!--<scope>test</scope>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.hectorclient</groupId>-->
<!--<artifactId>hector-core</artifactId>-->
<!--<version>$hector-core.version</version>-->
<!--<exclusions>-->
<!--<exclusion>-->
<!--<artifactId>commons-logging</artifactId>-->
<!--<groupId>commons-logging</groupId>-->
<!--</exclusion>-->
<!--</exclusions>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.datastax.cassandra</groupId>-->
<!--<artifactId>cassandra-driver-core</artifactId>-->
<!--<version>$cassandra-driver-core.version</version>-->
<!--<optional>true</optional>-->
<!--</dependency>-->
<!-- end::tests -->
</dependencies>

<properties>
<java.version>1.8</java.version>
<cassandra-driver-core.version>3.6.0</cassandra-driver-core.version>
<cassandra-unit-spring.version>2.1.9.2</cassandra-unit-spring.version>
<cassandra-unit-shaded.version>2.1.9.2</cassandra-unit-shaded.version>
<hector-core.version>2.0-0</hector-core.version>
<guava.version>19.0</guava.version>
<gt.version>18.0</gt.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>







</plugins>
</build>


<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>


<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

</project>


i have set up a cassandra.properties file setting the host and port and keyspacename, also there is a cassandra config java class that sets the connection parameters to connect to the cluster
here is the file:



package hello;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.data.cassandra.config.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.config.CassandraClusterFactoryBean;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;


@Configuration
public class CassandraConfig extends AbstractCassandraConfiguration
private static final Log LOGGER = LogFactory.getLog(CassandraConfig.class);

@Autowired
private Environment environment;

@Override
protected String getKeyspaceName()
return environment.getProperty("spring.data.cassandra.keyspace-name");


@Override
@Bean
public CassandraClusterFactoryBean cluster()
final CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
cluster.setContactPoints(environment.getProperty("spring.data.cassandra.contact-points"));
cluster.setPort(Integer.parseInt(environment.getProperty("spring.data.cassandra.port")));
LOGGER.info("Cluster created with contact points [" + environment.getProperty("spring.data.cassandra.contact-points") + "] " + "& port [" + Integer.parseInt(environment.getProperty("spring.data.cassandra.port")) + "].");
return cluster;


//
// @Bean
// public CassandraClusterFactoryBean cluster()
// CassandraClusterFactoryBean cluster =
// new CassandraClusterFactoryBean();
// cluster.setContactPoints("192.168.164.130");
// cluster.setPort(9042);
// return cluster;
//

@Override
@Bean
public CassandraMappingContext cassandraMapping() throws ClassNotFoundException
return new BasicCassandraMappingContext();


// @Bean
// public CassandraMappingContext cassandraMapping()
// throws ClassNotFoundException
// return new BasicCassandraMappingContext();
//



what else am i missing ?



EDIT : it turned out that i had to change the rpc_address in the cassandra.yml file in the vm host from localhost to the vm ip address, so its exposed to external connections










share|improve this question















i am using a spring boot quick start and want to establish a connection to a cassandra instance that is running on an ubuntu VM on the same machine,
i get this error when running the spring boot app



 . ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _
( ( )___ | '_ | '_| | '_ / _` |
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |___, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.5.RELEASE)

2018-11-08 18:00:10.671 INFO 12076 --- [ main] hello.Application : Starting Application on DESKTOP-OG0KPA1 with PID 12076 (C:Usersomar_Downloadsgs-spring-boot-mastergs-spring-boot-mastercompletetargetclasses started by omar_ in C:Usersomar_Downloadsgs-spring-boot-mastergs-spring-boot-mastercomplete)
2018-11-08 18:00:10.680 INFO 12076 --- [ main] hello.Application : No active profile set, falling back to default profiles: default
2018-11-08 18:00:10.966 INFO 12076 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@60dcc9fe: startup date [Thu Nov 08 18:00:10 EET 2018]; root of context hierarchy
2018-11-08 18:00:12.701 INFO 12076 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'cassandraTemplate' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=cassandraConfig; factoryMethodName=cassandraTemplate; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [hello/CassandraConfig.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration; factoryMethodName=cassandraTemplate; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.class]]
2018-11-08 18:00:13.020 INFO 12076 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2018-11-08 18:00:13.112 INFO 12076 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2018-11-08 18:00:14.517 INFO 12076 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8087 (http)
2018-11-08 18:00:14.560 INFO 12076 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-11-08 18:00:14.561 INFO 12076 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.34
2018-11-08 18:00:14.570 INFO 12076 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:Program FilesJavajdk1.8.0_121bin;C:WINDOWSSunJavabin;C:WINDOWSsystem32;C:WINDOWS;C:Program FilesDellDW WLAN Card;C:ProgramDataOracleJavajavapath;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:Program Files (x86)Bracketscommand;C:Program Files (x86)GtkSharp2.12bin;C:Program Files (x86)Gitcmd;C:Program Filesnodejs;C:PostgreSQLpg10bin;C:Program FilesPuTTY;C:WINDOWSSystem32OpenSSH;D:PostgreSQLpg10bin;C:Usersomar_Downloadsapache-maven-3.5.4-binapache-maven-3.5.4bin;C:Usersomar_AppDataLocalatombin;C:Usersomar_AppDataLocalMicrosoftWindowsApps;C:Usersomar_AppDataRoamingnpm;C:Program FilesMicrosoft VS Codebin;C:Usersomar_Downloadsapache-cassandra-3.11.3-binapache-cassandra-3.11.3bin;C:Python27;;.]
2018-11-08 18:00:14.775 INFO 12076 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-11-08 18:00:14.775 INFO 12076 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3830 ms
2018-11-08 18:00:15.491 ERROR 12076 --- [ost-startStop-1] o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthEndpoint]: Factory method 'healthEndpoint' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthIndicatorAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cluster' defined in class path resource [hello/CassandraConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.cassandra.config.CassandraClusterFactoryBean]: Factory method 'cluster' threw exception; nested exception is java.lang.NumberFormatException: null
2018-11-08 18:00:15.522 INFO 12076 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-11-08 18:00:15.534 WARN 12076 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2018-11-08 18:00:15.560 INFO 12076 --- [ main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-11-08 18:00:15.583 ERROR 12076 --- [ main] o.s.boot.SpringApplication : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1277) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1265) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at hello.Application.main(Application.java:15) [classes/:na]
Caused by: java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:542) ~[na:1.8.0_121]
at java.lang.Integer.parseInt(Integer.java:615) ~[na:1.8.0_121]
at hello.CassandraConfig.cluster(CassandraConfig.java:32) ~[classes/:na]
at hello.CassandraConfig$$EnhancerBySpringCGLIB$$bf5637d0.CGLIB$cluster$0(<generated>) ~[classes/:na]
at hello.CassandraConfig$$EnhancerBySpringCGLIB$$bf5637d0$$FastClassBySpringCGLIB$$bfd61920.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:365) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at hello.CassandraConfig$$EnhancerBySpringCGLIB$$bf5637d0.cluster(<generated>) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
... 122 common frames omitted


Process finished with exit code 1


here is my pom.xml:



<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.springframework</groupId>
<artifactId>gs-spring-boot</artifactId>
<version>0.1.0</version>



<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- tag::actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- end::actuator -->
<!-- tag::tests -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

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


<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-opengis</artifactId>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-data</artifactId>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-epsg-hsql</artifactId>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-wfs-ng</artifactId>
<version>$gt.version</version>
</dependency>

<!--<dependency>-->
<!--<groupId>org.apache.cassandra</groupId>-->
<!--<artifactId>cassandra-all</artifactId>-->
<!--<version>3.11.3</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.datastax.cassandra</groupId>-->
<!--<artifactId>cassandra-driver-core</artifactId>-->
<!--<version>3.6.0</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.springframework.data</groupId>-->
<!--<artifactId>spring-data-cassandra</artifactId>-->
<!--</dependency>-->

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


<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>


<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.6.0</version>
</dependency>

<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>



<!--<dependency>-->
<!--<groupId>org.cassandraunit</groupId>-->
<!--<artifactId>cassandra-unit-spring</artifactId>-->
<!--<version>$cassandra-unit-spring.version</version>-->
<!--<scope>test</scope>-->
<!--<exclusions>-->
<!--<exclusion>-->
<!--<groupId>org.cassandraunit</groupId>-->
<!--<artifactId>cassandra-unit</artifactId>-->
<!--</exclusion>-->
<!--</exclusions>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.cassandraunit</groupId>-->
<!--<artifactId>cassandra-unit-shaded</artifactId>-->
<!--<version>$cassandra-unit-shaded.version</version>-->
<!--<scope>test</scope>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.hectorclient</groupId>-->
<!--<artifactId>hector-core</artifactId>-->
<!--<version>$hector-core.version</version>-->
<!--<exclusions>-->
<!--<exclusion>-->
<!--<artifactId>commons-logging</artifactId>-->
<!--<groupId>commons-logging</groupId>-->
<!--</exclusion>-->
<!--</exclusions>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.datastax.cassandra</groupId>-->
<!--<artifactId>cassandra-driver-core</artifactId>-->
<!--<version>$cassandra-driver-core.version</version>-->
<!--<optional>true</optional>-->
<!--</dependency>-->
<!-- end::tests -->
</dependencies>

<properties>
<java.version>1.8</java.version>
<cassandra-driver-core.version>3.6.0</cassandra-driver-core.version>
<cassandra-unit-spring.version>2.1.9.2</cassandra-unit-spring.version>
<cassandra-unit-shaded.version>2.1.9.2</cassandra-unit-shaded.version>
<hector-core.version>2.0-0</hector-core.version>
<guava.version>19.0</guava.version>
<gt.version>18.0</gt.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>







</plugins>
</build>


<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>


<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

</project>


i have set up a cassandra.properties file setting the host and port and keyspacename, also there is a cassandra config java class that sets the connection parameters to connect to the cluster
here is the file:



package hello;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.data.cassandra.config.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.config.CassandraClusterFactoryBean;
import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;


@Configuration
public class CassandraConfig extends AbstractCassandraConfiguration
private static final Log LOGGER = LogFactory.getLog(CassandraConfig.class);

@Autowired
private Environment environment;

@Override
protected String getKeyspaceName()
return environment.getProperty("spring.data.cassandra.keyspace-name");


@Override
@Bean
public CassandraClusterFactoryBean cluster()
final CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
cluster.setContactPoints(environment.getProperty("spring.data.cassandra.contact-points"));
cluster.setPort(Integer.parseInt(environment.getProperty("spring.data.cassandra.port")));
LOGGER.info("Cluster created with contact points [" + environment.getProperty("spring.data.cassandra.contact-points") + "] " + "& port [" + Integer.parseInt(environment.getProperty("spring.data.cassandra.port")) + "].");
return cluster;


//
// @Bean
// public CassandraClusterFactoryBean cluster()
// CassandraClusterFactoryBean cluster =
// new CassandraClusterFactoryBean();
// cluster.setContactPoints("192.168.164.130");
// cluster.setPort(9042);
// return cluster;
//

@Override
@Bean
public CassandraMappingContext cassandraMapping() throws ClassNotFoundException
return new BasicCassandraMappingContext();


// @Bean
// public CassandraMappingContext cassandraMapping()
// throws ClassNotFoundException
// return new BasicCassandraMappingContext();
//



what else am i missing ?



EDIT : it turned out that i had to change the rpc_address in the cassandra.yml file in the vm host from localhost to the vm ip address, so its exposed to external connections







java spring spring-boot cassandra






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 12:34

























asked Nov 8 at 16:11









omarshiha

66




66







  • 1




    From the obvious in your post, the problem is caused by this line: cluster.setPort(Integer.parseInt(environment.getProperty("spring.data.cassandra.port")));. And that can be the case only if environment.getProperty("spring.data.cassandra.port") returns null. Just make sure that your port config entry is properly configured and accessible.
    – ernest_k
    Nov 8 at 17:18










  • github.com/girdhar-singh-rathore/…
    – Girdhar Singh Rathore
    Nov 8 at 19:27










  • still gives the same error : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerController': Unsatisfied dependency expressed through field 'customerService';
    – omarshiha
    Nov 8 at 20:33










  • Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /192.168.164.130:9042 (com.datastax.driver.core.exceptions.TransportException: [/192.168.164.130:9042] Cannot connect))
    – omarshiha
    Nov 8 at 20:33












  • 1




    From the obvious in your post, the problem is caused by this line: cluster.setPort(Integer.parseInt(environment.getProperty("spring.data.cassandra.port")));. And that can be the case only if environment.getProperty("spring.data.cassandra.port") returns null. Just make sure that your port config entry is properly configured and accessible.
    – ernest_k
    Nov 8 at 17:18










  • github.com/girdhar-singh-rathore/…
    – Girdhar Singh Rathore
    Nov 8 at 19:27










  • still gives the same error : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerController': Unsatisfied dependency expressed through field 'customerService';
    – omarshiha
    Nov 8 at 20:33










  • Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /192.168.164.130:9042 (com.datastax.driver.core.exceptions.TransportException: [/192.168.164.130:9042] Cannot connect))
    – omarshiha
    Nov 8 at 20:33







1




1




From the obvious in your post, the problem is caused by this line: cluster.setPort(Integer.parseInt(environment.getProperty("spring.data.cassandra.port")));. And that can be the case only if environment.getProperty("spring.data.cassandra.port") returns null. Just make sure that your port config entry is properly configured and accessible.
– ernest_k
Nov 8 at 17:18




From the obvious in your post, the problem is caused by this line: cluster.setPort(Integer.parseInt(environment.getProperty("spring.data.cassandra.port")));. And that can be the case only if environment.getProperty("spring.data.cassandra.port") returns null. Just make sure that your port config entry is properly configured and accessible.
– ernest_k
Nov 8 at 17:18












github.com/girdhar-singh-rathore/…
– Girdhar Singh Rathore
Nov 8 at 19:27




github.com/girdhar-singh-rathore/…
– Girdhar Singh Rathore
Nov 8 at 19:27












still gives the same error : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerController': Unsatisfied dependency expressed through field 'customerService';
– omarshiha
Nov 8 at 20:33




still gives the same error : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerController': Unsatisfied dependency expressed through field 'customerService';
– omarshiha
Nov 8 at 20:33












Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /192.168.164.130:9042 (com.datastax.driver.core.exceptions.TransportException: [/192.168.164.130:9042] Cannot connect))
– omarshiha
Nov 8 at 20:33




Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /192.168.164.130:9042 (com.datastax.driver.core.exceptions.TransportException: [/192.168.164.130:9042] Cannot connect))
– omarshiha
Nov 8 at 20:33












3 Answers
3






active

oldest

votes

















up vote
0
down vote













You spring.data.cassandra.port is missing or null. You can change to below code so that if it is not present then the code will use the default



@Value("$spring.data.cassandra.port: <cassandra port/9042>")
private int port;





share|improve this answer




















  • i have replaced it with this : @Bean public CassandraClusterFactoryBean cluster() CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean(); cluster.setContactPoints("192.168.164.130"); cluster.setPort(9042); return cluster; still got this error : Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /192.168.164.130:9042 (com.datastax.driver.core.exceptions.TransportException: [/192.168.164.130:9042] Cannot connect))
    – omarshiha
    Nov 8 at 18:55










  • Looks like protocol version mismatch. Are your using the same Cassandra version's jar. I am adding my Cassandra configuration. Or you can call .setProtocolVersion(<int value>) to set the protocol version. Also adding my configuration class
    – Debopam
    Nov 8 at 19:04










  • Also please check the port on which Cassandra in listening. It may be different e.g. 9142
    – Debopam
    Nov 8 at 19:05











  • the port and the versions are correct, i double checked them
    – omarshiha
    Nov 8 at 19:18

















up vote
0
down vote













import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.data.cassandra.config.CassandraClusterFactoryBean;
import org.springframework.data.cassandra.config.java.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;


/**
* @author dpoddar
*
*/
@Configuration
@EnableCassandraRepositories(basePackages = "com.xxx.abc.reposiroty.cassandra")
@ComponentScan(basePackages = "com.xxx.abc")
@Profile("cassandra")
public class CassandraConfig extends AbstractCassandraConfiguration
private static final Log LOGGER = LogFactory.getLog(CassandraConfig.class);

@Override
protected String getKeyspaceName()
return "agenthub";



@Override
@Bean
public CassandraClusterFactoryBean cluster()
final CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
cluster.setContactPoints("localhost");
cluster.setPort(9042);
//LOGGER.info("Cluster created with contact points [" + environment.getProperty("cassandra.contactpoints") + "] " + "& port [" + Integer.parseInt(environment.getProperty("cassandra.port")) + "].");
return cluster;


@Override
@Bean
public CassandraMappingContext cassandraMapping() throws ClassNotFoundException
return new BasicCassandraMappingContext();







share|improve this answer






















  • No dependencies. That is package to scan. Changed it
    – Debopam
    Nov 8 at 19:24










  • it still giving red error on AbstractAgentHierarchy and CassandraAgentHierarchyService, what are the packages or how to import ?
    – omarshiha
    Nov 8 at 19:47










  • Those are mycustom musiness class. You can safely remove those classes. Updated the code.
    – Debopam
    Nov 8 at 19:52











  • Also, getKeyspaceName() should have your space name.
    – Debopam
    Nov 8 at 19:54

















up vote
0
down vote













You are adding a lot of boilerplate code that Spring handles for you, as long as your application.yml has the following properties:



spring:
data:
cassandra:
contact-points:
keyspace-name:
username:
password:
port:


and the dependency



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


Spring will configure the connection for you, similar to Spring data for RDBMS.



You can then use the Cassandra Repository to query your tables:



@Repository
public interface YourRepository extends CassandraRepository<Item>
//



And entity:



@Table
public class Item
@PrimaryKeyColumn(
name = "id"
type = PrimaryKeyType.CLUSTERED)
private UUID id;
@PrimaryKeyColumn(
name = "key", type = PrimaryKeyType.PARTITIONED)
private String key;
@Column
private String data;
//Getter setters






share|improve this answer






















  • Go to start.spring.io and add Cassandra as a dependency for a starter project
    – danzdoran
    Nov 8 at 17:59










  • i already did all of this of course.
    – omarshiha
    Nov 8 at 18:56










  • Ok you can remove your CassandraConfig class then as it is not needed. You only need @EnableCassandraRepositories anywhere in your app.
    – danzdoran
    Nov 8 at 19:06










  • no i need it cuz by default it will try to connect to localhost:port , but my case is that cassandra is running on a vm with different ip not localhost
    – omarshiha
    Nov 8 at 19:44










  • In your property file set the ip and port spring: data: cassandra: contact-points: <vm ip> keyspace-name: username: password: port: <vm port>
    – danzdoran
    Nov 8 at 19:54











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53211731%2fspring-boot-cant-connect-to-cassandra-database%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













You spring.data.cassandra.port is missing or null. You can change to below code so that if it is not present then the code will use the default



@Value("$spring.data.cassandra.port: <cassandra port/9042>")
private int port;





share|improve this answer




















  • i have replaced it with this : @Bean public CassandraClusterFactoryBean cluster() CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean(); cluster.setContactPoints("192.168.164.130"); cluster.setPort(9042); return cluster; still got this error : Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /192.168.164.130:9042 (com.datastax.driver.core.exceptions.TransportException: [/192.168.164.130:9042] Cannot connect))
    – omarshiha
    Nov 8 at 18:55










  • Looks like protocol version mismatch. Are your using the same Cassandra version's jar. I am adding my Cassandra configuration. Or you can call .setProtocolVersion(<int value>) to set the protocol version. Also adding my configuration class
    – Debopam
    Nov 8 at 19:04










  • Also please check the port on which Cassandra in listening. It may be different e.g. 9142
    – Debopam
    Nov 8 at 19:05











  • the port and the versions are correct, i double checked them
    – omarshiha
    Nov 8 at 19:18














up vote
0
down vote













You spring.data.cassandra.port is missing or null. You can change to below code so that if it is not present then the code will use the default



@Value("$spring.data.cassandra.port: <cassandra port/9042>")
private int port;





share|improve this answer




















  • i have replaced it with this : @Bean public CassandraClusterFactoryBean cluster() CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean(); cluster.setContactPoints("192.168.164.130"); cluster.setPort(9042); return cluster; still got this error : Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /192.168.164.130:9042 (com.datastax.driver.core.exceptions.TransportException: [/192.168.164.130:9042] Cannot connect))
    – omarshiha
    Nov 8 at 18:55










  • Looks like protocol version mismatch. Are your using the same Cassandra version's jar. I am adding my Cassandra configuration. Or you can call .setProtocolVersion(<int value>) to set the protocol version. Also adding my configuration class
    – Debopam
    Nov 8 at 19:04










  • Also please check the port on which Cassandra in listening. It may be different e.g. 9142
    – Debopam
    Nov 8 at 19:05











  • the port and the versions are correct, i double checked them
    – omarshiha
    Nov 8 at 19:18












up vote
0
down vote










up vote
0
down vote









You spring.data.cassandra.port is missing or null. You can change to below code so that if it is not present then the code will use the default



@Value("$spring.data.cassandra.port: <cassandra port/9042>")
private int port;





share|improve this answer












You spring.data.cassandra.port is missing or null. You can change to below code so that if it is not present then the code will use the default



@Value("$spring.data.cassandra.port: <cassandra port/9042>")
private int port;






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 8 at 18:04









Debopam

98221638




98221638











  • i have replaced it with this : @Bean public CassandraClusterFactoryBean cluster() CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean(); cluster.setContactPoints("192.168.164.130"); cluster.setPort(9042); return cluster; still got this error : Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /192.168.164.130:9042 (com.datastax.driver.core.exceptions.TransportException: [/192.168.164.130:9042] Cannot connect))
    – omarshiha
    Nov 8 at 18:55










  • Looks like protocol version mismatch. Are your using the same Cassandra version's jar. I am adding my Cassandra configuration. Or you can call .setProtocolVersion(<int value>) to set the protocol version. Also adding my configuration class
    – Debopam
    Nov 8 at 19:04










  • Also please check the port on which Cassandra in listening. It may be different e.g. 9142
    – Debopam
    Nov 8 at 19:05











  • the port and the versions are correct, i double checked them
    – omarshiha
    Nov 8 at 19:18
















  • i have replaced it with this : @Bean public CassandraClusterFactoryBean cluster() CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean(); cluster.setContactPoints("192.168.164.130"); cluster.setPort(9042); return cluster; still got this error : Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /192.168.164.130:9042 (com.datastax.driver.core.exceptions.TransportException: [/192.168.164.130:9042] Cannot connect))
    – omarshiha
    Nov 8 at 18:55










  • Looks like protocol version mismatch. Are your using the same Cassandra version's jar. I am adding my Cassandra configuration. Or you can call .setProtocolVersion(<int value>) to set the protocol version. Also adding my configuration class
    – Debopam
    Nov 8 at 19:04










  • Also please check the port on which Cassandra in listening. It may be different e.g. 9142
    – Debopam
    Nov 8 at 19:05











  • the port and the versions are correct, i double checked them
    – omarshiha
    Nov 8 at 19:18















i have replaced it with this : @Bean public CassandraClusterFactoryBean cluster() CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean(); cluster.setContactPoints("192.168.164.130"); cluster.setPort(9042); return cluster; still got this error : Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /192.168.164.130:9042 (com.datastax.driver.core.exceptions.TransportException: [/192.168.164.130:9042] Cannot connect))
– omarshiha
Nov 8 at 18:55




i have replaced it with this : @Bean public CassandraClusterFactoryBean cluster() CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean(); cluster.setContactPoints("192.168.164.130"); cluster.setPort(9042); return cluster; still got this error : Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /192.168.164.130:9042 (com.datastax.driver.core.exceptions.TransportException: [/192.168.164.130:9042] Cannot connect))
– omarshiha
Nov 8 at 18:55












Looks like protocol version mismatch. Are your using the same Cassandra version's jar. I am adding my Cassandra configuration. Or you can call .setProtocolVersion(<int value>) to set the protocol version. Also adding my configuration class
– Debopam
Nov 8 at 19:04




Looks like protocol version mismatch. Are your using the same Cassandra version's jar. I am adding my Cassandra configuration. Or you can call .setProtocolVersion(<int value>) to set the protocol version. Also adding my configuration class
– Debopam
Nov 8 at 19:04












Also please check the port on which Cassandra in listening. It may be different e.g. 9142
– Debopam
Nov 8 at 19:05





Also please check the port on which Cassandra in listening. It may be different e.g. 9142
– Debopam
Nov 8 at 19:05













the port and the versions are correct, i double checked them
– omarshiha
Nov 8 at 19:18




the port and the versions are correct, i double checked them
– omarshiha
Nov 8 at 19:18












up vote
0
down vote













import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.data.cassandra.config.CassandraClusterFactoryBean;
import org.springframework.data.cassandra.config.java.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;


/**
* @author dpoddar
*
*/
@Configuration
@EnableCassandraRepositories(basePackages = "com.xxx.abc.reposiroty.cassandra")
@ComponentScan(basePackages = "com.xxx.abc")
@Profile("cassandra")
public class CassandraConfig extends AbstractCassandraConfiguration
private static final Log LOGGER = LogFactory.getLog(CassandraConfig.class);

@Override
protected String getKeyspaceName()
return "agenthub";



@Override
@Bean
public CassandraClusterFactoryBean cluster()
final CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
cluster.setContactPoints("localhost");
cluster.setPort(9042);
//LOGGER.info("Cluster created with contact points [" + environment.getProperty("cassandra.contactpoints") + "] " + "& port [" + Integer.parseInt(environment.getProperty("cassandra.port")) + "].");
return cluster;


@Override
@Bean
public CassandraMappingContext cassandraMapping() throws ClassNotFoundException
return new BasicCassandraMappingContext();







share|improve this answer






















  • No dependencies. That is package to scan. Changed it
    – Debopam
    Nov 8 at 19:24










  • it still giving red error on AbstractAgentHierarchy and CassandraAgentHierarchyService, what are the packages or how to import ?
    – omarshiha
    Nov 8 at 19:47










  • Those are mycustom musiness class. You can safely remove those classes. Updated the code.
    – Debopam
    Nov 8 at 19:52











  • Also, getKeyspaceName() should have your space name.
    – Debopam
    Nov 8 at 19:54














up vote
0
down vote













import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.data.cassandra.config.CassandraClusterFactoryBean;
import org.springframework.data.cassandra.config.java.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;


/**
* @author dpoddar
*
*/
@Configuration
@EnableCassandraRepositories(basePackages = "com.xxx.abc.reposiroty.cassandra")
@ComponentScan(basePackages = "com.xxx.abc")
@Profile("cassandra")
public class CassandraConfig extends AbstractCassandraConfiguration
private static final Log LOGGER = LogFactory.getLog(CassandraConfig.class);

@Override
protected String getKeyspaceName()
return "agenthub";



@Override
@Bean
public CassandraClusterFactoryBean cluster()
final CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
cluster.setContactPoints("localhost");
cluster.setPort(9042);
//LOGGER.info("Cluster created with contact points [" + environment.getProperty("cassandra.contactpoints") + "] " + "& port [" + Integer.parseInt(environment.getProperty("cassandra.port")) + "].");
return cluster;


@Override
@Bean
public CassandraMappingContext cassandraMapping() throws ClassNotFoundException
return new BasicCassandraMappingContext();







share|improve this answer






















  • No dependencies. That is package to scan. Changed it
    – Debopam
    Nov 8 at 19:24










  • it still giving red error on AbstractAgentHierarchy and CassandraAgentHierarchyService, what are the packages or how to import ?
    – omarshiha
    Nov 8 at 19:47










  • Those are mycustom musiness class. You can safely remove those classes. Updated the code.
    – Debopam
    Nov 8 at 19:52











  • Also, getKeyspaceName() should have your space name.
    – Debopam
    Nov 8 at 19:54












up vote
0
down vote










up vote
0
down vote









import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.data.cassandra.config.CassandraClusterFactoryBean;
import org.springframework.data.cassandra.config.java.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;


/**
* @author dpoddar
*
*/
@Configuration
@EnableCassandraRepositories(basePackages = "com.xxx.abc.reposiroty.cassandra")
@ComponentScan(basePackages = "com.xxx.abc")
@Profile("cassandra")
public class CassandraConfig extends AbstractCassandraConfiguration
private static final Log LOGGER = LogFactory.getLog(CassandraConfig.class);

@Override
protected String getKeyspaceName()
return "agenthub";



@Override
@Bean
public CassandraClusterFactoryBean cluster()
final CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
cluster.setContactPoints("localhost");
cluster.setPort(9042);
//LOGGER.info("Cluster created with contact points [" + environment.getProperty("cassandra.contactpoints") + "] " + "& port [" + Integer.parseInt(environment.getProperty("cassandra.port")) + "].");
return cluster;


@Override
@Bean
public CassandraMappingContext cassandraMapping() throws ClassNotFoundException
return new BasicCassandraMappingContext();







share|improve this answer














import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.data.cassandra.config.CassandraClusterFactoryBean;
import org.springframework.data.cassandra.config.java.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;


/**
* @author dpoddar
*
*/
@Configuration
@EnableCassandraRepositories(basePackages = "com.xxx.abc.reposiroty.cassandra")
@ComponentScan(basePackages = "com.xxx.abc")
@Profile("cassandra")
public class CassandraConfig extends AbstractCassandraConfiguration
private static final Log LOGGER = LogFactory.getLog(CassandraConfig.class);

@Override
protected String getKeyspaceName()
return "agenthub";



@Override
@Bean
public CassandraClusterFactoryBean cluster()
final CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
cluster.setContactPoints("localhost");
cluster.setPort(9042);
//LOGGER.info("Cluster created with contact points [" + environment.getProperty("cassandra.contactpoints") + "] " + "& port [" + Integer.parseInt(environment.getProperty("cassandra.port")) + "].");
return cluster;


@Override
@Bean
public CassandraMappingContext cassandraMapping() throws ClassNotFoundException
return new BasicCassandraMappingContext();








share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 8 at 19:53

























answered Nov 8 at 19:04









Debopam

98221638




98221638











  • No dependencies. That is package to scan. Changed it
    – Debopam
    Nov 8 at 19:24










  • it still giving red error on AbstractAgentHierarchy and CassandraAgentHierarchyService, what are the packages or how to import ?
    – omarshiha
    Nov 8 at 19:47










  • Those are mycustom musiness class. You can safely remove those classes. Updated the code.
    – Debopam
    Nov 8 at 19:52











  • Also, getKeyspaceName() should have your space name.
    – Debopam
    Nov 8 at 19:54
















  • No dependencies. That is package to scan. Changed it
    – Debopam
    Nov 8 at 19:24










  • it still giving red error on AbstractAgentHierarchy and CassandraAgentHierarchyService, what are the packages or how to import ?
    – omarshiha
    Nov 8 at 19:47










  • Those are mycustom musiness class. You can safely remove those classes. Updated the code.
    – Debopam
    Nov 8 at 19:52











  • Also, getKeyspaceName() should have your space name.
    – Debopam
    Nov 8 at 19:54















No dependencies. That is package to scan. Changed it
– Debopam
Nov 8 at 19:24




No dependencies. That is package to scan. Changed it
– Debopam
Nov 8 at 19:24












it still giving red error on AbstractAgentHierarchy and CassandraAgentHierarchyService, what are the packages or how to import ?
– omarshiha
Nov 8 at 19:47




it still giving red error on AbstractAgentHierarchy and CassandraAgentHierarchyService, what are the packages or how to import ?
– omarshiha
Nov 8 at 19:47












Those are mycustom musiness class. You can safely remove those classes. Updated the code.
– Debopam
Nov 8 at 19:52





Those are mycustom musiness class. You can safely remove those classes. Updated the code.
– Debopam
Nov 8 at 19:52













Also, getKeyspaceName() should have your space name.
– Debopam
Nov 8 at 19:54




Also, getKeyspaceName() should have your space name.
– Debopam
Nov 8 at 19:54










up vote
0
down vote













You are adding a lot of boilerplate code that Spring handles for you, as long as your application.yml has the following properties:



spring:
data:
cassandra:
contact-points:
keyspace-name:
username:
password:
port:


and the dependency



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


Spring will configure the connection for you, similar to Spring data for RDBMS.



You can then use the Cassandra Repository to query your tables:



@Repository
public interface YourRepository extends CassandraRepository<Item>
//



And entity:



@Table
public class Item
@PrimaryKeyColumn(
name = "id"
type = PrimaryKeyType.CLUSTERED)
private UUID id;
@PrimaryKeyColumn(
name = "key", type = PrimaryKeyType.PARTITIONED)
private String key;
@Column
private String data;
//Getter setters






share|improve this answer






















  • Go to start.spring.io and add Cassandra as a dependency for a starter project
    – danzdoran
    Nov 8 at 17:59










  • i already did all of this of course.
    – omarshiha
    Nov 8 at 18:56










  • Ok you can remove your CassandraConfig class then as it is not needed. You only need @EnableCassandraRepositories anywhere in your app.
    – danzdoran
    Nov 8 at 19:06










  • no i need it cuz by default it will try to connect to localhost:port , but my case is that cassandra is running on a vm with different ip not localhost
    – omarshiha
    Nov 8 at 19:44










  • In your property file set the ip and port spring: data: cassandra: contact-points: <vm ip> keyspace-name: username: password: port: <vm port>
    – danzdoran
    Nov 8 at 19:54















up vote
0
down vote













You are adding a lot of boilerplate code that Spring handles for you, as long as your application.yml has the following properties:



spring:
data:
cassandra:
contact-points:
keyspace-name:
username:
password:
port:


and the dependency



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


Spring will configure the connection for you, similar to Spring data for RDBMS.



You can then use the Cassandra Repository to query your tables:



@Repository
public interface YourRepository extends CassandraRepository<Item>
//



And entity:



@Table
public class Item
@PrimaryKeyColumn(
name = "id"
type = PrimaryKeyType.CLUSTERED)
private UUID id;
@PrimaryKeyColumn(
name = "key", type = PrimaryKeyType.PARTITIONED)
private String key;
@Column
private String data;
//Getter setters






share|improve this answer






















  • Go to start.spring.io and add Cassandra as a dependency for a starter project
    – danzdoran
    Nov 8 at 17:59










  • i already did all of this of course.
    – omarshiha
    Nov 8 at 18:56










  • Ok you can remove your CassandraConfig class then as it is not needed. You only need @EnableCassandraRepositories anywhere in your app.
    – danzdoran
    Nov 8 at 19:06










  • no i need it cuz by default it will try to connect to localhost:port , but my case is that cassandra is running on a vm with different ip not localhost
    – omarshiha
    Nov 8 at 19:44










  • In your property file set the ip and port spring: data: cassandra: contact-points: <vm ip> keyspace-name: username: password: port: <vm port>
    – danzdoran
    Nov 8 at 19:54













up vote
0
down vote










up vote
0
down vote









You are adding a lot of boilerplate code that Spring handles for you, as long as your application.yml has the following properties:



spring:
data:
cassandra:
contact-points:
keyspace-name:
username:
password:
port:


and the dependency



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


Spring will configure the connection for you, similar to Spring data for RDBMS.



You can then use the Cassandra Repository to query your tables:



@Repository
public interface YourRepository extends CassandraRepository<Item>
//



And entity:



@Table
public class Item
@PrimaryKeyColumn(
name = "id"
type = PrimaryKeyType.CLUSTERED)
private UUID id;
@PrimaryKeyColumn(
name = "key", type = PrimaryKeyType.PARTITIONED)
private String key;
@Column
private String data;
//Getter setters






share|improve this answer














You are adding a lot of boilerplate code that Spring handles for you, as long as your application.yml has the following properties:



spring:
data:
cassandra:
contact-points:
keyspace-name:
username:
password:
port:


and the dependency



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


Spring will configure the connection for you, similar to Spring data for RDBMS.



You can then use the Cassandra Repository to query your tables:



@Repository
public interface YourRepository extends CassandraRepository<Item>
//



And entity:



@Table
public class Item
@PrimaryKeyColumn(
name = "id"
type = PrimaryKeyType.CLUSTERED)
private UUID id;
@PrimaryKeyColumn(
name = "key", type = PrimaryKeyType.PARTITIONED)
private String key;
@Column
private String data;
//Getter setters







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 8 at 19:56

























answered Nov 8 at 17:58









danzdoran

1165




1165











  • Go to start.spring.io and add Cassandra as a dependency for a starter project
    – danzdoran
    Nov 8 at 17:59










  • i already did all of this of course.
    – omarshiha
    Nov 8 at 18:56










  • Ok you can remove your CassandraConfig class then as it is not needed. You only need @EnableCassandraRepositories anywhere in your app.
    – danzdoran
    Nov 8 at 19:06










  • no i need it cuz by default it will try to connect to localhost:port , but my case is that cassandra is running on a vm with different ip not localhost
    – omarshiha
    Nov 8 at 19:44










  • In your property file set the ip and port spring: data: cassandra: contact-points: <vm ip> keyspace-name: username: password: port: <vm port>
    – danzdoran
    Nov 8 at 19:54

















  • Go to start.spring.io and add Cassandra as a dependency for a starter project
    – danzdoran
    Nov 8 at 17:59










  • i already did all of this of course.
    – omarshiha
    Nov 8 at 18:56










  • Ok you can remove your CassandraConfig class then as it is not needed. You only need @EnableCassandraRepositories anywhere in your app.
    – danzdoran
    Nov 8 at 19:06










  • no i need it cuz by default it will try to connect to localhost:port , but my case is that cassandra is running on a vm with different ip not localhost
    – omarshiha
    Nov 8 at 19:44










  • In your property file set the ip and port spring: data: cassandra: contact-points: <vm ip> keyspace-name: username: password: port: <vm port>
    – danzdoran
    Nov 8 at 19:54
















Go to start.spring.io and add Cassandra as a dependency for a starter project
– danzdoran
Nov 8 at 17:59




Go to start.spring.io and add Cassandra as a dependency for a starter project
– danzdoran
Nov 8 at 17:59












i already did all of this of course.
– omarshiha
Nov 8 at 18:56




i already did all of this of course.
– omarshiha
Nov 8 at 18:56












Ok you can remove your CassandraConfig class then as it is not needed. You only need @EnableCassandraRepositories anywhere in your app.
– danzdoran
Nov 8 at 19:06




Ok you can remove your CassandraConfig class then as it is not needed. You only need @EnableCassandraRepositories anywhere in your app.
– danzdoran
Nov 8 at 19:06












no i need it cuz by default it will try to connect to localhost:port , but my case is that cassandra is running on a vm with different ip not localhost
– omarshiha
Nov 8 at 19:44




no i need it cuz by default it will try to connect to localhost:port , but my case is that cassandra is running on a vm with different ip not localhost
– omarshiha
Nov 8 at 19:44












In your property file set the ip and port spring: data: cassandra: contact-points: <vm ip> keyspace-name: username: password: port: <vm port>
– danzdoran
Nov 8 at 19:54





In your property file set the ip and port spring: data: cassandra: contact-points: <vm ip> keyspace-name: username: password: port: <vm port>
– danzdoran
Nov 8 at 19:54


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53211731%2fspring-boot-cant-connect-to-cassandra-database%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế