I want to use Cassandra 3.x in a Spring boot project. I found out that the current version of the Spring Data Cassandra project only supports Cassandra 2.x. So I wanted to use the DataStax driver instead of the Spring Data Cassandra project. I added
compile 'com.datastax.cassandra:cassandra-driver-core:3.1.1'
like addiction. Now I can embed values ββin a key space in a Cassandra cluster. But when I run tests for the REST controller, I get an error
java.lang.NoClassDefFoundError: io/netty/handler/codec/http/FullHttpRequest
So I added
compile 'io.netty:netty-all:4.1.6.Final'
like addiction, and the error has disappeared. But now all the tests using
TestRestTemplate.postForObject(...)
or
TestRestTemplate.put(...)
fail. But using
TestRestTemplate.getForObject(...)
works as expected. I assume that there is some clash in the dependencies of Spring Boot and the version of Netty, which I added as a dependency.
I found out that the latest version of the DataStax Cassandra driver to work without the Netty add-on is 2.1.5, dated March 2015 and not supporting Cassandra 3. Using this driver, everything works, but I donβt want to use the old driver.
UPDATE: I removed the DataStax driver dependency and tried to use version 1.57.M1 Spring Data Cassandra and override the versions of the Data Cassandra and Cassandra Spring, Spring drivers in buildscript.
ext['spring.version'] = '5.0.0.M2' ext['spring-data-releasetrain.version'] = 'Ingalls-M1' ext['cassandra-driver.version'] = '3.1.1'
This led to the following error:
java.lang.NoClassDefFoundError: io/netty/util/Timer
when using Cassandra functionality. When I turn Netty back on, the Cassandra functionality works, but my tests using TestRestTemplate.put
and .post
no longer run. I gave him another attempt to upgrade to Spring Boot Version 2.0.0.BUILD-SNAPSHOT, which also includes Spring Data Cassandra 1.5.0.M1. Now, when I launch the application and use the functionality of the DataStax Driver, I get the same NoClassDefFoundError as before. Adding Netty as a dependency again kills my TestRestTemplate test cases ...
UPDATE: TestRestTemplate
does not work because Spring Boot configures it to use Netty4ClientHttpRequestFactory
when it finds Netty in the classpath and Netty4ClientHttpRequestFactory
does not seem to work.
See https://github.com/spring-projects/spring-boot/issues/7240 and https://jira.spring.io/browse/SPR-14860
For a fix, see my answer to this question.