首页 > 解决方案 > 避免 Spring Boot App 在启动时连接到 Cassandra

问题描述

我有一个 Spring Boot 应用程序,它存储/重试来自 Cassandra DB 的数据。但是如果 Cassandra 不可用,则 Spring 应用程序不会启动。

这是我的代码 - https://github.com/simplyatul/springcassandrajunit

我正在玩 DemoTableRepo.java。如果我注释掉

@RepositoryDefinition(domainClass = DemoTable.class, idClass = String.class)

然后 Spring Boot 应用程序在没有连接到 Cassandra 的情况下启动,但是当 Repo 用于检索/存储调用时,它会引发以下异常

java.lang.IllegalArgumentException: Interface org.simplyatul.cassandrajunit.repository.DemoTableRepo must be annotated with @org.springframework.data.repository.RepositoryDefinition!

如果我保留以下行注释

@RepositoryDefinition(domainClass = DemoTable.class, idClass = String.class)

然后 Spring boot 应用程序尝试在启动时连接到 Cassandra 并且无法启动。

我发现了类似的链接/问题,但提供的解决方案无法正常工作。我错过了什么吗?提前致谢。

我们如何阻止spring boot data cassandra连接到localhost?

即使Cassandra关闭,如何加载spring应用程序上下文

标签: springspring-bootcassandra-3.0

解决方案


推荐阅读