spring boot cassandra“创建名为'session'的bean时出错”

3hvapo4f  于 2021-06-15  发布在  Cassandra
关注(0)|答案(1)|浏览(227)

我对简单的spring引导应用程序有问题。我正在使用:
spring boot starter父级
Spring启动机数据cassandra
cassandra 3.11.3(在centos 7服务器和本地mac os上)(由cqlsh works查询)
我遵循了一个简单的指南https://www.baeldung.com/spring-data-cassandra-tutorial 不管cassandra是在运行还是不运行,我在启动时都会得到一个错误:

2018-11-25 09:12:34.581 ERROR 83213 --- [main] o.s.boot.SpringApplication: Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'session' defined in class path resource [some/project/path/CassandraConfig.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: com/codahale/metrics/JmxReporte

我的配置类:

@Configuration
@EnableCassandraRepositories(basePackages = "packagename")
public class CassandraConfig extends AbstractCassandraConfiguration {

    @Override
    protected String getKeyspaceName() {
        return "test";
    }

    @Bean
    public CassandraClusterFactoryBean cluster() {
        CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
        cluster.setContactPoints("127.0.0.1");
        cluster.setPort(9042);
        return cluster;
    }

    @Override
    public SchemaAction getSchemaAction() {
        return SchemaAction.CREATE_IF_NOT_EXISTS;
    }

    @Override
    public String[] getEntityBasePackages() {
        return new String[]{"packagename"};
    }
}

实体:

@Table
public class Image implements Serializable {

    @PrimaryKeyColumn(
        name = "key",
        ordinal = 0,
        type = PrimaryKeyType.PARTITIONED)
    private UUID id;

    @Column
    private Blob object;
}

存储库:

@Repository
public interface ImagesRepository extends CrudRepository<Image, UUID> {
}

Cassandra结构:

CREATE TABLE images (
    key text,
    object blob,
    PRIMARY KEY (key)
);

也https://github.com/springframeworkguru/spring-boot-cassandra-example 在创建bean时也给了我一个错误。

pengsaosao

pengsaosao1#

缺少dropwizard依赖项:
您需要度量核心库作为依赖项:

<dependencies>
<dependency>
    <groupId>io.dropwizard.metrics</groupId>
    <artifactId>metrics-core</artifactId>
    <version>${metrics.version}</version>
</dependency>

笔记
确保在pom中声明了metrics.version属性,当前版本为3.1.0。

相关问题