Spring-data-cassandra:创建名称为“ sessionFactory”的bean时出错,并且无法解析对bean“ cassandraTemplate”的引用 [英] Spring-data-cassandra: Error creating bean with name 'sessionFactory' and Cannot resolve reference to bean 'cassandraTemplate'

查看:396
本文介绍了Spring-data-cassandra:创建名称为“ sessionFactory”的bean时出错,并且无法解析对bean“ cassandraTemplate”的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个springboot应用程序,正在其中连接到cassandra DB。

I have a springboot app, in which I am connecting to cassandra DB.

我的pom.xml:

parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.6.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-cassandra</artifactId>
    </dependency>

cassandraConfig定义:

The cassandraConfig definitition:

@Configuration
@PropertySource("file:///Users/s1b03vf/Work/carrierhub/cass.properties")
@ConfigurationProperties()
@EnableCassandraRepositories(basePackageClasses = {MCSEDistributorRepository.class})
public class MSCECassandraConfig {
protected String contactPoints;

protected int port;

protected String username;

protected String password;

protected String keyspace;


@Override
protected AuthProvider getAuthProvider() {
    return new PlainTextAuthProvider(username, password);
}


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


@Override
protected String getContactPoints() {
    return contactPoints;
}


@Override
protected int getPort() {
    return port;
}


@Override
public String[] getEntityBasePackages() {
    return new String[]{"com.example.demo.entity.cassandra"};
}
}

存储库类别:

@Repository
public interface MCSEDistributorRepository extends CassandraRepository<MCSEDistributor, String> {

}

实体类:

    @Table("mcse_offer")
    public class MCSEDistributor {
        @Column
        @PrimaryKey
        private int id;

        @Column
        private String name;
}

现在,当我启动应用程序时,遇到以下错误:

Now when I start my application I am running into the below error:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'documentationPluginsBootstrapper' defined in URL [jar:file:/Users/s1b03vf/.m2/repository/io/springfox/springfox-spring-web/2.9.2/springfox-spring-web-2.9.2.jar!/springfox/documentation/spring/web/plugins/DocumentationPluginsBootstrapper.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcRequestHandlerProvider' defined in URL [jar:file:/Users/s1b03vf/.m2/repository/io/springfox/springfox-spring-web/2.9.2/springfox-spring-web-2.9.2.jar!/springfox/documentation/spring/web/plugins/WebMvcRequestHandlerProvider.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Unsatisfied dependency expressed through method 'requestMappingHandlerMapping' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.format.support.FormattingConversionService]: Factory method 'mvcConversionService' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MCSEDistributorRepository': Cannot resolve reference to bean 'cassandraTemplate' while setting bean property 'cassandraTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraTemplate' defined in class path resource [com/example/demo/config/MSCECassandraConfig.class]: Bean instantiation via factory method failed; nested exception is 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/example/demo/config/MSCECassandraConfig.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/example/demo/config/MSCECassandraConfig.class]: Invocation of init method failed; nested exception is com.datastax.driver.core.exceptions.DriverInternalError: Unexpected exception thrown

和cassandraTemplate和sessionFactory的bean创建问题。我是使用spring-data的新手,所以不确定我在这里缺少什么。

It says dependency and bean creation issue for cassandraTemplate and sessionFactory. I am new to using spring-data, so not sure what I am missing here.

从启动日志中,我看到它正在使用以下驱动程序版本:

From startup log, I can see that it is using the below driver version:

2020-06-08 22:44:57.782  INFO 42129 --- [  restartedMain] com.datastax.driver.core                 : DataStax Java driver 3.7.2 for Apache Cassandra


推荐答案

尝试调用super,然后设置所需的属性

Try calling super and then set the required properties

@Bean
public CassandraClusterFactoryBean cluster() {
    CassandraClusterFactoryBean cluster = super.cluster();
    
    cluster.setContactPoints("127.0.0.1");
    cluster.setPort(9142);

    return cluster;
}

这篇关于Spring-data-cassandra:创建名称为“ sessionFactory”的bean时出错,并且无法解析对bean“ cassandraTemplate”的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆