Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

qianjizheng avatar image
qianjizheng asked qianjizheng commented

cqlSession Bean instantiation returns NoSuchMethodError

When I tried to use @Bean in spring boot to create CqlSession, I got the following error message. The core driver version used is 4.4.0;

@Configuration
public class CassandraConfig {

    @Bean
    public CqlSession cqlSession() {
        return CqlSession.builder()
                .addContactPoint(new InetSocketAddress(contactPoints, port))
                .withKeyspace(keyspace())
                .withSslContext(createSslContextWithTruststore())
                .withAuthCredentials(username, password)
                .withLocalDatacenter("DEVoce-DC2")
                .build();
    }
}
LN="o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext" MSG=Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cqlSession' defined in class path resource [*/CassandraConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.datastax.oss.driver.api.core.CqlSession]: Factory method 'cqlSession' threw exception; nested exception is java.lang.NoSuchMethodError: com.datastax.oss.protocol.internal.request.query.QueryOptions.<init>(ILjava/util/List;Ljava/util/Map;ZILjava/nio/ByteBuffer;IJLjava/lang/String;)V
spring-boot
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Cedrick Lunven avatar image
Cedrick Lunven answered qianjizheng commented

Yes you may use some Spring-Data configuration in your project. Unfortunately as of now the spring-data does not use the proper protocol.


Talk is cheap, show me the code. => You do have a full working sample here https://github.com/DataStax-Examples/spring-data-starter/blob/master/pom.xml


1 comment Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Thanks. Overriding native-protocol with 1.4.11 works.

0 Likes 0 ·
Tomasz Lelek avatar image
Tomasz Lelek answered

It seems that there is a mismatch between the java-driver and the native-protocol dependency:

<groupId>com.datastax.oss</groupId>
<artifactId>native-protocol</artifactId>

Could you check the version of the native-protocol that is used?

Alternatively, could you increment the java-driver to the most recent version?

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.