使用springboot获取cassandraconfig的度量异常

l7mqbcuq  于 2021-06-14  发布在  Cassandra
关注(0)|答案(1)|浏览(384)

我在应用程序启动期间遇到以下异常。 @EnableCassandraRepositories 是这个计划的一部分 Application 班级。我用的是Spring Data Cassandra。我尝试从不同的依赖项中排除度量,但没有一个有效。
下面是我使用的错误、配置代码和依赖项。

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'session' defined in class path resource [com/lte/assessmentanalytics/config/CassandraConfig.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: com/codahale/metrics/Metric

CassandraConfig

@Configuration
    public class CassandraConfig extends AbstractCassandraConfiguration {
        @Value("${cassandra.contactpoints}")
        private String contactPoints;
        @Value("${cassandra.port}")
        private int port;
        @Value("${cassandra.keyspace}")
        private String keySpace;
        @Value("${cassandra.basePackages}")
        private String basePackages;

        @Autowired
        private Environment environment;

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

        @Override
        @Bean
        public CassandraClusterFactoryBean cluster() {
            final CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
            cluster.setContactPoints(contactPoints);
            cluster.setPort(port);
            return cluster;
        }

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

依赖项

<dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-cassandra</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>com.datastax.cassandra</groupId>
                        <artifactId>cassandra-driver-core</artifactId>
                    </exclusion>
                        <exclusion>
                            <groupId>io.dropwizard.metrics</groupId>
                            <artifactId>metrics-core</artifactId>
                        </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>com.datastax.cassandra</groupId>
                <artifactId>cassandra-driver-core</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>io.dropwizard.metrics</groupId>
                        <artifactId>metrics-core</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>com.datastax.cassandra</groupId>
                <artifactId>cassandra-driver-mapping</artifactId>
            </dependency>
q8l4jmvw

q8l4jmvw1#

它似乎缺少codahale指标。尝试将此添加到pom:

<dependency>
     <groupId>com.codahale.metrics</groupId>
     <artifactId>metrics-core</artifactId>
     <version>3.0.2</version>
</dependency>

相关问题