Spring-data-cassandra:创建名称为“sessionFactory”的 bean 时出错,并且无法解析对 bean“cassandraTemplate”的引用

2024-05-11

我有一个 springboot 应用程序,在其中连接到 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>

卡桑德拉配置定义:

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

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

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 的新手,所以不确定我在这里缺少什么。

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

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

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

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

    return cluster;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring-data-cassandra:创建名称为“sessionFactory”的 bean 时出错,并且无法解析对 bean“cassandraTemplate”的引用 的相关文章

随机推荐

  • 消除“集成测试骗局” - 了解协作和合同测试

    我最近看过集成测试是一个骗局 http www infoq com presentations integration tests scam由 J B Rainsberger 撰写 现在正在寻找有关该主题的更多材料 我不得不说 我对我们做错
  • 在各种分辨率下通过百分比宽度将根 div 居中

    我需要通过基于百分比的宽度而不是基于像素的宽度将根 div 居中 container width 80 margin 0px auto 它将容器相对于页面居中 并在 1366 706 分辨率下正常工作 但在 1280 1024 下不起作用
  • 错误:NVIDIA-SMI 失败,因为无法与 NVIDIA 驱动程序通信

    NVIDIA SMI 抛出此错误 NVIDIA SMI 失败 因为无法与 NVIDIA 通信 司机 确保安装了最新的 NVIDIA 驱动程序并且 跑步 我清除了 NVIDIA 并按照提到的步骤重新安装了它here https askubun
  • 如何使用jsPDF设置图像以适合页面宽度?

    有什么办法可以解决这个问题吗 我尝试以毫米为单位设置宽度和高度 如何将其设置为全角 您可以获取 PDF 文档的宽度和高度 如下所示 var doc new jsPDF p mm a4 var width doc internal pageS
  • 如何在VB.NET中画一条线

    我正在尝试用 VB NET 画一条简单的线 我的代码如下 但是当我运行代码时 只显示表单 没有线 我在这里做错了什么 Public Class Form1 Dim pen As System Drawing Graphics Private
  • 准备编程竞赛的缩写和函数[关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • 是否可以动态导入模块?

    我有很多角度组件的导入 看起来我可以编写一个函数来简化导入 我只是不知道怎么做 但这应该很简单 进口样本 import DashboardComponent from app components dashboard dashboard c
  • 在浏览器中打开的 .mhtml 文件中填写输入

    我想对 mhtml 文件运行 e2e 测试 即填写表格 在 mhtml 文件上查看和提取数据效果非常好 但我无法填写任何内容input字段 既不是手动也不是通过木偶操作者 你可以用这个试试 mhtml 文件 https gist githu
  • 如何使用javascript通过类名更改html元素的值

    这是我用来更改 html 元素值的代码 a class classname href Vtech com This text to be chnage a 如何在页面加载瞬间更改此文本 看来你需要添加DOMContentLoaded或者把你
  • 在 Dart 中重写哈希码的好方法是什么?

    我发现自己想要覆盖对象的 hashcode 和 并且我想知道是否有最佳实践来实现依赖于多个属性的 hashcode 并且似乎有一些特定于 Dart 的注意事项 最简单的答案是将所有属性的哈希值异或在一起 这可能还不错 Dart Up 和 R
  • Android 改造参数化@Headers

    我正在使用 OAuth 每次发出请求时都需要将 OAuth 令牌放入标头中 我看到 Header注释 但是有没有办法让它参数化 以便我可以在运行时传入 这是概念 Header Authorization OAuth var api vers
  • 如何捕获生成器抛出的异常并恢复迭代?

    我有一个生成器 它将值的集合传递给方法并生成结果 调用的方法可能会返回异常 发生这种情况时 我希望异常转到调用生成器来处理异常的代码 然后继续循环生成器 为了说明这一点 下面是一个生成器的示例 它将产生1 抛出一个 Exception 然后
  • method_存在于父类php中

    我正在尝试使用 php 函数 method exists 但我需要检查该方法是否存在于对象的父类中 so class Parent public function myFunction class Child extends Parent
  • 如何在as3中不询问的情况下写入外部文件

    我有这个代码 var fileRef FileReference new FileReference fileRef save ciao coso lingua txt 在现有的 lingua txt 文件上写入 该脚本有效 但每次他保存时
  • 使用 https 的 Java Jersey RESTful Web 服务

    我是 Java EE 的新手 正在开发一个 RESTful API 其中每个 API 调用用户都会发送编码的凭据 我的问题是如何通过默认的 http 实现 https 协议并确保我的连接安全 我正在使用 Jersey Restful Web
  • php 中接口的用途是什么?

    如果我在 PHP 中定义一个接口 以及一个创建该接口实例的工厂类 有什么方法可以强制客户端代码仅使用该接口而不使用底层具体类 根据我的理解 客户也可以实际使用底层类中的任何公共函数 字段 这是一个例子
  • HTML 中按钮内的图标

    我需要在 HTML 中将小图标放在按钮内 例如 我需要在我的网站上有 facebook 按钮 在按钮内首先是 F 图标 然后是 facebook 怎么做
  • Linux命令列出所有可用命令和别名

    是否有一个 Linux 命令可以列出该终端会话的所有可用命令和别名 就好像您输入 a 并按下 Tab 键一样 但针对的是字母表中的每个字母 或者运行 别名 但也返回命令 为什么 我想运行以下命令并查看命令是否可用 ListAllComman
  • 2D 中的大量旋转

    我正在尝试使用 Bevy 0 3 并且我可以轻松使用内置转换Camera2dComponents default 这是自上而下的二维 问题在于尝试将玩家的旋转与鼠标同步 for event in evreader iter cursor m
  • Spring-data-cassandra:创建名称为“sessionFactory”的 bean 时出错,并且无法解析对 bean“cassandraTemplate”的引用

    我有一个 springboot 应用程序 在其中连接到 cassandra DB 我的 pom xml parent gt