简体   繁体   中英

Unable to connect to cassandra using CassandraConfiguration

I have followed the CassandraOperations for inserting the records into cassandra. Since I need to insert TTL value for a row I have opted this way. CrudRespository cannot have the functionality of storing TTL value.

Below is the Cassandra Config Class

@Override
@Bean
public CassandraClusterFactoryBean cluster() {
    final CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
    cluster.setContactPoints(cassandra_contactPoints);
    cluster.setPort(Integer.parseInt(cassandra_port));
    cluster.setUsername(cassandra_username);
    cluster.setPassword(cassandra_password);
    LOGGER.info("Cluster created with contact points [" + cassandra_port + "] " + "& port ["
            + Integer.parseInt(cassandra_port) + "].");
    return cluster;
}

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

@Override
protected String getKeyspaceName() {
    return cassandra_keyspaceName;
}

When I start the application it is throwing the below exceptions

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.cassandra.core.CassandraAdminTemplate]: Factory method 'cassandraTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/sample/session/config/CassandraConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.cassandra.SessionFactory]: Factory method 'sessionFactory' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'session' defined in class path resource [com/sample/session/config/CassandraConfig.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: com/codahale/metrics/JmxReporter 
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.cassandra.SessionFactory]: Factory method 'sessionFactory' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'session' defined in class path resource [com/sample/session/config/CassandraConfig.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: com/codahale/metrics/JmxReporter
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'session' defined in class path resource [com/sample/session/config/CassandraConfig.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: com/codahale/metrics/JmxReporter
Caused by: java.lang.ClassNotFoundException: com.codahale.metrics.JmxReporter

This is documented in Java driver's documentation - you either need to create a cluster object without JMX metrics reporting - this is done by adding call .withoutJMXReporting() to cluster builder, or add the Maven dependency:

<dependency>
  <groupId>io.dropwizard.metrics</groupId>
  <artifactId>metrics-jmx</artifactId>
  <version>4.0.2</version>
</dependency>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM