Spring Boot Data Embedded Cassandra

We use on the project Cassandra + Spring Boot. Here are the steps which worked for us:

a) Configure you test like this

import org.cassandraunit.spring.CassandraDataSet;
import org.cassandraunit.spring.CassandraUnitDependencyInjectionTestExecutionListener;
import org.cassandraunit.spring.CassandraUnitTestExecutionListener;
import org.cassandraunit.spring.EmbeddedCassandra;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class)
@TestExecutionListeners(listeners = {
    CassandraUnitDependencyInjectionTestExecutionListener.class,
    CassandraUnitTestExecutionListener.class,
    ServletTestExecutionListener.class,
    DependencyInjectionTestExecutionListener.class,
    DirtiesContextTestExecutionListener.class
})
@EmbeddedCassandra(timeout = 60000)
@CassandraDataSet(value = {"bootstrap_test.cql"}, keyspace = "local_test")
public abstract class BaseTest {

b) in your src/test/resources/application.properties, add this (please note, embedded cassandra starts on port 9142, but not on default 9042)

spring.data.cassandra.port=9142
spring.data.cassandra.keyspace-name=local_test

c) Create empty file bootstrap_test.cql in src/test/resources

d) Add to your pom.xml

    <dependency>
        <groupId>org.cassandraunit</groupId>
        <artifactId>cassandra-unit-spring</artifactId>
        <version>${cassandra-unit.version}</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.cassandraunit</groupId>
                <artifactId>cassandra-unit</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.cassandraunit</groupId>
        <artifactId>cassandra-unit-spring</artifactId>
        <version>${cassandra-unit.version}</version>
    </dependency>

This should be enough to run your tests with Embedded Cassandra. Hope it helps.


There is no embedded Apache Cassandra support in Spring Boot available and it's not planned. There's little demand for embedded Apache Cassandra on the one hand, on the other hand, Apache Cassandra comes with a lot of dependencies that conflict with Boot's other dependencies.

Take a look at Cassandra Unit.

You can also build an own test rule when using JUnit tests that gives you full control over the Apache Cassandra version, runtime behavior and so on. Take a look at a possible implementation: CassandraRule.java.