簡體   English   中英

無法使用CassandraConfiguration連接到cassandra

[英]Unable to connect to cassandra using CassandraConfiguration

我遵循了CassandraOperations將記錄插入cassandra的操作。 由於我需要在一行中插入TTL值,因此我選擇了這種方式。 CrudRespository無法具有存儲TTL值的功能。

下面是Cassandra Config類

@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;
}

當我啟動應用程序時,它拋出以下異常

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

這在Java驅動程序的文檔中進行了說明 -您可能需要創建不包含JMX度量標准報告的集群對象-這可以通過將調用.withoutJMXReporting()添加到集群構建器中來完成,或者添加Maven依賴項來完成:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM