Spring Data Cassandra1.5.x+Spring4.3.x连接Cassandra3.0遇AbstractMethodError求助
Let's break down what's causing this error and walk through the solutions to get your Cassandra connection working again.
Root Cause
The Java.lang.AbstractMethodError happens because of a version compatibility mismatch between Spring Framework 4.3.x and Spring Data Cassandra 1.5.x:
- Spring Framework 4.3.x updated the
AnnotatedElementUtilsclass to call theisAnnotationPresent(Class<? extends Annotation>)method on annotated parameters. - However, Spring Data Cassandra 1.5.x's
CassandraParameters$AnnotatedParameterclass (which implementsAnnotatedElement) doesn't provide an implementation for this method. At runtime, when the JVM tries to invoke this unimplemented abstract method, it throws the error you're seeing.
Solutions
1. Downgrade Spring Framework to 4.2.x (Recommended)
Spring Data Cassandra 1.5.x is officially compatible with Spring Framework 4.2.x, not 4.3.x. Rolling back your Spring version to a 4.2.x release (like 4.2.9.RELEASE) will resolve the method mismatch immediately.
Maven Dependency Example:
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.2.9.RELEASE</version> </dependency> <!-- Update all other Spring core dependencies to match this version -->
Gradle Dependency Example:
implementation 'org.springframework:spring-context:4.2.9.RELEASE' // Sync all related Spring dependencies to use 4.2.9.RELEASE
2. Upgrade Spring Data Cassandra (If Java Version Allows)
If you can upgrade your project to Java 1.8+, you can bump Spring Data Cassandra to version 1.6.x or higher. These versions are built to work with Spring Framework 4.3.x and include the missing isAnnotationPresent implementation.
Note: This option isn't feasible if you're stuck on Java 1.7, as Spring Data Cassandra 1.6.x requires Java 1.8.
3. Temporary Custom Patch (Not Recommended)
If you can't modify dependency versions right now, you can create a custom subclass of CassandraParameters.AnnotatedParameter to implement the missing method. This is a workaround and carries maintenance risks, but it can get you up and running in an emergency:
import org.springframework.data.cassandra.repository.query.CassandraParameters; import java.lang.annotation.Annotation; public class CustomAnnotatedParameter extends CassandraParameters.AnnotatedParameter { public CustomAnnotatedParameter(CassandraParameters parameters, int index) { super(parameters, index); } @Override public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) { // Delegate to the underlying annotated element return getAnnotatedElement().isAnnotationPresent(annotationType); } }
You'll need to override the parameter resolution logic in Spring Data Cassandra to use this custom class, but this involves tinkering with internal framework code—so only use this if the first two options are impossible.
内容的提问来源于stack exchange,提问作者user2402081

