我已经按照 CassandraOperations 将记录插入到 cassandra 中。因为我需要为一行插入 TTL 值,所以我选择了这种方式。CrudRespository 不能有存储 TTL 值的功能。下面是 Cassandra 配置类@Override@Beanpublic 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@Beanpublic CassandraMappingContext cassandraMapping() throws ClassNotFoundException {    return new BasicCassandraMappingContext();}@Overrideprotected 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 
                    
                    
                1 回答
 
                    
                    
                            蓝山帝景
                            
                                
                            
                        
                        
                                                
                    TA贡献1843条经验 获得超7个赞
这记录在Java 驱动程序的文档中——您需要创建一个没有 JMX 指标报告的集群对象——这是通过添加.withoutJMXReporting()对集群构建器的调用或添加 Maven 依赖项来完成的:
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-jmx</artifactId>
<version>4.0.2</version>
</dependency>
添加回答
举报
0/150
	提交
		取消
	