我试图在Sping Boot 中运行Apache-Spark查询来从Cassandra中检索数据,但以下问题一直在我的终端上弹出。
注意:连接到cassandra成功。
- Sping Boot 版本:2.7.4
- java版本:8
- Spark版本:3.2.0
可以在result1.show下面的服务文件中的“www.example.com()”中找到此异常。
在这里查看我的代码:
// my service
@Override
public byte[] getAllDataSpark() {
SparkSession spark = SparkSession.builder()
.appName(sparkAppName)
.master(sparkMaster)
.config("spark.cassandra.connection.host" ,"10.1.7.43" )
.config("spark.executor.instances" ,"4" )
.config("spark.executor.memory" ,"10G" )
.config("spark.driver.memory","5G")
.config("spark.cassandra.read.timeoutMS" ,"1200000")
.getOrCreate();
Dataset<Row> df = spark.read()
.format("org.apache.spark.sql.cassandra")
.option("keyspace", "datacrowd")
.option("table", "loc_location_main_data")
.load();
df.createOrReplaceTempView("viewTable");
Dataset<Row> result = spark.sql("SELECT * FROM viewTable LIMIT 10");
Dataset<Object> result1 = result.as(Encoders.bean(Object.class));
result1.show();
return result1.toString().getBytes();
}
//我的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.4</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.valoores.cassandra</groupId>
<artifactId>cassandra-spark</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>cassandra-spark</name>
<description>datacrowd-cassandra</description>
<properties>
<java.version>8</java.version>
<!-- <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> -->
</properties>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.0.Final</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20210307</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
<!-- Spark and Cassandra dependencies -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.12</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>com.datastax.spark</groupId>
<artifactId>spark-cassandra-connector-driver_2.12</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>com.datastax.spark</groupId>
<artifactId>spark-cassandra-connector_2.12</artifactId>
<version>3.2.0</version>
</dependency
>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.12</artifactId>
<version>3.2.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
根据我的研究,我尝试添加以下依赖项:
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-core</artifactId>
<version>4.9.0</version>
</dependency>
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-query-builder</artifactId>
<version>4.9.0</version>
</dependency>
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-core-shaded</artifactId>
<version>4.9.0</version>
</dependency>
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-mapper-runtime</artifactId>
<version>4.9.0</version>
</dependency>
我试了几个版本,但问题仍然存在。
1条答案
按热度按时间mo49yndu1#
NoClassDefFoundError
通常表示与项目中的依赖项存在冲突。Spring Boot 2.7.4 uses Cassandra Java driver 4.14.1。另一方面,Spark Cassandra连接器使用Cassandra Java驱动4.13.0。
但说实话,很难知道问题出在哪里,因为您没有提供完整的错误消息和完整的堆栈跟踪。此外,包含一个复制问题的最小代码示例也很重要。干杯!