Skip to content

Instantly share code, notes, and snippets.

@kazusato
Last active January 11, 2020 10:55
Show Gist options
  • Save kazusato/a9b4ee4708738fcbcfee55d0e5315845 to your computer and use it in GitHub Desktop.
Save kazusato/a9b4ee4708738fcbcfee55d0e5315845 to your computer and use it in GitHub Desktop.
Disabling autoconfiguration for Cassandra on Spring Boot Test

Purpose

When we run SpringBootTest annotated tests with Spring Data Cassandra, Cassndra conneciton is configured automatically. However, some tests do not need such connection and, if you do not have a Cassandra server to connect, your tests will fail. This document explains how you can configure JUnit tests not to connect to Cassandra in a Spring Data Cassandra enabled project.

Add an annotation to your test class

If you would like to disable autoconfiguration for Cassandra, you should add the following annotation to your test class:

@SpringBootTest
@EnableAutoConfiguration(exclude = [CassandraAutoConfiguration::class] )
class YourTests {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment