Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CassandraAutoConfiguration is executed when it should be disabled [DATACASS-826] #993

Closed
spring-projects-issues opened this issue Nov 13, 2020 · 2 comments
Assignees
Labels
in: core status: invalid

Comments

@spring-projects-issues
Copy link

spring-projects-issues commented Nov 13, 2020

porunov opened DATACASS-826 and commented

The project depends on Spring Boot Starter Web

compile ("org.springframework.boot:spring-boot-starter-web:2.3.2.RELEASE") {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
exclude group: 'junit', module: 'junit'
exclude group: 'org.springframework.data', module: 'spring-data-cassandra-parent'
exclude group: 'org.springframework.data', module: 'spring-data-cassandra'
exclude group: 'com.datastax.oss', module: 'java-driver-core'
}

compile ("org.springframework.boot:spring-boot-starter-data-jpa:2.3.2.RELEASE") {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
exclude group: 'junit', module: 'junit'
exclude group: 'org.springframework.data', module: 'spring-data-cassandra-parent'
exclude group: 'org.springframework.data', module: 'spring-data-cassandra'
exclude group: 'com.datastax.oss', module: 'java-driver-core'
}
compile ("org.springframework:spring-aop:5.2.8.RELEASE") {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
exclude group: 'junit', module: 'junit'
exclude group: 'org.springframework.data', module: 'spring-data-cassandra-parent'
exclude group: 'org.springframework.data', module: 'spring-data-cassandra'
exclude group: 'com.datastax.oss', module: 'java-driver-core'
}
compile ("org.springframework:spring-aspects:5.2.8.RELEASE") {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
exclude group: 'junit', module: 'junit'
exclude group: 'org.springframework.data', module: 'spring-data-cassandra-parent'
exclude group: 'org.springframework.data', module: 'spring-data-cassandra'
exclude group: 'com.datastax.oss', module: 'java-driver-core'
}

 

 

The project also depends on DataStax Cassandra drivers 4.9.0 and 3.10.2. Notice, DataStax Cassandra Driver 4.x and 3.x are binary incompatible and share different classpath. They don't conflict and thus both versions can be included in the same project. Out project must include both versions because some dependencies depend on one version and other dependencies depend on another version. Moreover, the project directly depend on 3.10.2 version.

We include both drivers into the classpath:

compile ("com.datastax.cassandra:cassandra-driver-core:3.10.2"){
exclude group: 'com.github.jnr', module: 'jnr-ffi'
exclude group: 'com.github.jnr', module: 'jnr-posix'
exclude group: 'io.dropwizard.metrics', module: 'metrics-core'
exclude group: 'io.netty', module: 'netty-handler'
}
compile ("com.datastax.cassandra:cassandra-driver-mapping:3.10.2"){
exclude group: 'com.github.jnr', module: 'jnr-ffi'
exclude group: 'com.github.jnr', module: 'jnr-posix'
exclude group: 'io.dropwizard.metrics', module: 'metrics-core'
exclude group: 'io.netty', module: 'netty-handler'
}
compile ("com.datastax.cassandra:cassandra-driver-extras:3.10.2")
compile ("com.datastax.oss:java-driver-core:4.9.0")
compile ("com.datastax.oss:java-driver-query-builder:4.9.0")

 

Unfortunately, when we try to create a Session bean like this:

@Primary
@Bean(destroyMethod = "close")
public Session cassandraSession(Cluster cassandraCluster) {
   return cassandraCluster.connect();
}

 

We receive an error:

The bean 'cassandraSession', defined in class path resource [org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [x/y/z/configuration/ColumnDatabaseConfiguration.class] and overriding is disabled.

 

As seen above, we excluded spring-data-cassandra from dependencies but it still tries to autoconfigure Cassandra beans.

We also tried to exclude Spring cassandra configuration classes but they are still being used:

@SpringBootApplication(scanBasePackages = "x.y.z", exclude = {CassandraDataAutoConfiguration.class, CassandraReactiveDataAutoConfiguration.class})

 

We also suspect that this behaviour might be caused by Spring Dependency Management Plugin.

buildscript {
dependencies {
classpath ("io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE")
}
}

 

Or Spring Boot Gradle Plugin:

buildscript {
dependencies {
classpath ("org.springframework.boot:spring-boot-gradle-plugin:2.3.2.RELEASE")
}
}

 

 

Any workarounds / thoughts on how to disable automatic Cassandra Session Bean Creation is highly appreciated


No further details from DATACASS-826

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Nov 13, 2020

porunov commented

I've found an issue. I had to exclude CassandraAutoConfiguration but I was excluding CassandraDataAutoConfiguration.

I.e. it has to be like:

@SpringBootApplication(scanBasePackages = "x.y.z", exclude = { CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class })

 

After excluding CassandraAutoConfiguration Cassandra Session Bean is not automatically created (as expected). Thus, the issue is resolved

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Nov 14, 2020

Mark Paluch commented

Thanks for letting us know. In any case, that's a Spring Boot issue

@spring-projects-issues spring-projects-issues added status: invalid in: core labels Dec 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core status: invalid
Projects
None yet
Development

No branches or pull requests

2 participants