java.lang.NoClassDefFoundError: com/datastax/oss/driver/api/mapper/entity/naming/GetterStyle

huangapple go评论69阅读模式
英文:

java.lang.NoClassDefFoundError: com/datastax/oss/driver/api/mapper/entity/naming/GetterStyle

问题

我正在使用Spring Boot和Gradle 7.6构建Cassandra DataStax 4.14。

Gradle文件:

plugins {
    id 'java'
    id 'org.springframework.boot' version '2.3.5.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'io.freefair.lombok' version '6.6.3'
}

dependencies {
   ...

    implementation 'io.github.lognet:grpc-spring-boot-starter:4.5.4'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-webflux'

    // Cassandra
    annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
    annotationProcessor group: 'com.datastax.oss', name: 'java-driver-mapper-processor', version: cassandraSdkVersion

    implementation "com.datastax.oss:java-driver-mapper-runtime:4.14.0"
    implementation "com.datastax.oss:java-driver-core:4.14.0"
    implementation "com.datastax.oss:java-driver-query-builder:4.14.0"
    compileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion
    // 强制使用原生协议
    implementation "com.datastax.oss:native-protocol:1.5.1"

    ...
}

我的代码的简单示例:

import com.datastax.oss.driver.api.mapper.annotations.Mapper;
import com.datastax.oss.driver.api.mapper.annotations.DaoFactory;
import com.datastax.oss.driver.api.mapper.annotations.DaoKeyspace;
import com.datastax.oss.driver.api.mapper.annotations.DaoTable;
import com.datastax.oss.driver.api.mapper.annotations.Dao;
import com.datastax.oss.driver.api.core.CqlSession;

@Mapper
public interface CassandraMapper {

    static CassandraMapper build(CqlSession session) {
        return new CassandraMapper(session).build();
    }

    @DaoFactory
    ExampleDao exampleDao(@DaoKeyspace String keyspace, @DaoTable String table);
}

实体类:

import lombok.Builder;
import lombok.Data;
import com.datastax.oss.driver.api.mapper.annotations.Entity;
import com.datastax.oss.driver.api.mapper.annotations.PartitionKey;

@Data
@Builder
@Entity
public class EntityObject {
    @PartitionKey private long id;
    private Long version;
}

当我尝试运行gradle compileJava时,我收到以下错误消息:

java.lang.NoClassDefFoundError: com/datastax/oss/driver/api/mapper/entity/naming/GetterStyle

我尝试配置annotationProcessor,并阅读了文档 https://docs.datastax.com/en/developer/java-driver/4.14/manual/mapper/config/lombok/https://github.com/DataStax-Examples/object-mapper-jvm/tree/master/lombok,但似乎找不到任何问题。

英文:

I am building Cassandra datastax 4.14 with Spring Boot and gradle 7.6

Gradle file:

plugins {
    id 'java'
    id 'org.springframework.boot' version "2.3.5.RELEASE"
    id 'io.spring.dependency-management' version "1.0.9.RELEASE"
    id "io.freefair.lombok" version "6.6.3"
}


dependencies {
   ...

    implementation 'io.github.lognet:grpc-spring-boot-starter:4.5.4'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-webflux'

    // Cassandra
    annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
    annotationProcessor group: 'com.datastax.oss', name: 'java-driver-mapper-processor', version: cassandraSdkVersion

    implementation "com.datastax.oss:java-driver-mapper-runtime:4.14.0"
    implementation "com.datastax.oss:java-driver-core:4.14.0"
    implementation "com.datastax.oss:java-driver-query-builder:4.14.0"
    compileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion
    // Force native protocol.
    implementation "com.datastax.oss:native-protocol:1.5.1"

    ...
}

Simple Example of my code

import com.datastax.oss.driver.api.mapper.annotations.Mapper;
import com.datastax.oss.driver.api.mapper.annotations.DaoFactory;
import com.datastax.oss.driver.api.mapper.annotations.DaoKeyspace;
import com.datastax.oss.driver.api.mapper.annotations.DaoTable;
import com.datastax.oss.driver.api.mapper.annotations.Dao;
import com.datastax.oss.driver.api.core.CqlSession;

@Mapper
public interface CassandraMapper {

    static CassandraMapper build(CqlSession session) {
        return new CassandraMapper(session).build();
    }

    @DaoFactory
    ExampleDao exampleDao(@DaoKeyspace String keyspace, @DaoTable String table);
}

Entity

import lombok.Builder;
import lombok.Data;
import com.datastax.oss.driver.api.mapper.annotations.Entity;
import com.datastax.oss.driver.api.mapper.annotations.PartitionKey;

@Data
@Builder
@Entity
public class EntityObject {
    @PartitionKey private long id;
    private Long version;
}

When I try to run gradle compileJava, I get the error:
java.lang.NoClassDefFoundError: com/datastax/oss/driver/api/mapper/entity/naming/GetterStyle

I've tried configuring annotationProcessor, I've read the docs at https://docs.datastax.com/en/developer/java-driver/4.14/manual/mapper/config/lombok/ and
https://github.com/DataStax-Examples/object-mapper-jvm/tree/master/lombok, but I can't seem to find any issues.

答案1

得分: 0

看起来是 Spring 依赖管理降级了我的映射器库。

我在我的 Gradle 文件中添加了 annotationProcessor "com.datastax.oss:java-driver-mapper-runtime:4.14.0" 以强制使用正确的版本,现在可以构建了。

英文:

It looks like spring dependency management was downgrading my mapper library.

I added annotationProcessor "com.datastax.oss:java-driver-mapper-runtime:4.14.0" to my gradle file to force the correct version, and it builds now.

huangapple
  • 本文由 发表于 2023年6月9日 10:33:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76436839.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定