无法弄清楚如何让 docker 成功构建。 我在 Spring Data DynamoDB 依赖项中尝试了一堆不同的版本号,并且尝试一起使用不同的 groupId(不是
com.github.derjust
)。
似乎我只是缺少 dynamo db 和 pom.xml 语法的正确组合,但对于 java 和 Maven 来说是全新的,我不知道它可能是什么。
pom.xml 文件
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<!-- Spring Boot dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- AWS SDK for DynamoDB -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>dynamodb</artifactId>
<version>2.16.32</version>
</dependency>
<!-- Spring Data DynamoDB -->
<dependency>
<groupId>com.github.derjust</groupId>
<artifactId>spring-data-dynamodb</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Transaction.java 文件
package com.example.model;
import org.springframework.data.annotation.Id;
import org.springframework.data.dynamodb.core.mapping.DynamoDBHashKey;
import org.springframework.data.dynamodb.core.mapping.DynamoDBTable;
@DynamoDBTable(tableName = "Transactions")
public class Transaction {
@Id
@DynamoDBHashKey
private String transactionId;
private String accountId;
private double amount;
private String date;
private String description;
public Transaction() {}
public Transaction(String transactionId, String accountId, double amount, String date, String description) {
this.transactionId = transactionId;
this.accountId = accountId;
this.amount = amount;
this.date = date;
this.description = description;
}
// Getters and Setters
}
跑步后
docker-compose up -d --build
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.5.4:run (default-cli) > test-compile @ demo >>>
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to /workspace/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /workspace/src/main/java/com/example/model/Transaction.java:[4,54] package org.springframework.data.dynamodb.core.mapping does not exist
[ERROR] /workspace/src/main/java/com/example/model/Transaction.java:[5,54] package org.springframework.data.dynamodb.core.mapping does not exist
[ERROR] /workspace/src/main/java/com/example/model/Transaction.java:[7,2] cannot find symbol
symbol: class DynamoDBTable
[ERROR] /workspace/src/main/java/com/example/model/Account.java:[4,54] package org.springframework.data.dynamodb.core.mapping does not exist
[ERROR] /workspace/src/main/java/com/example/model/Account.java:[5,54] package org.springframework.data.dynamodb.core.mapping does not exist
[ERROR] /workspace/src/main/java/com/example/model/Account.java:[7,2] cannot find symbol
symbol: class DynamoDBTable
[ERROR] /workspace/src/main/java/com/example/model/User.java:[4,54] package org.springframework.data.dynamodb.core.mapping does not exist
[ERROR] /workspace/src/main/java/com/example/model/User.java:[5,54] package org.springframework.data.dynamodb.core.mapping does not exist
[ERROR] /workspace/src/main/java/com/example/model/User.java:[7,2] cannot find symbol
symbol: class DynamoDBTable
[ERROR] /workspace/src/main/java/com/example/model/Transaction.java:[10,6] cannot find symbol
symbol: class DynamoDBHashKey
location: class com.example.model.Transaction
[ERROR] /workspace/src/main/java/com/example/model/Account.java:[10,6] cannot find symbol
symbol: class DynamoDBHashKey
location: class com.example.model.Account
[ERROR] /workspace/src/main/java/com/example/model/User.java:[10,6] cannot find symbol
symbol: class DynamoDBHashKey
location: class com.example.model.User
[INFO] 12 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.495 s
[INFO] Finished at: 2024-06-25T13:38:30Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project demo: Compilation failure: Compilation failure:
[ERROR] /workspace/src/main/java/com/example/model/Transaction.java:[4,54] package org.springframework.data.dynamodb.core.mapping does not exist
[ERROR] /workspace/src/main/java/com/example/model/Transaction.java:[5,54] package org.springframework.data.dynamodb.core.mapping does not exist
[ERROR] /workspace/src/main/java/com/example/model/Transaction.java:[7,2] cannot find symbol
[ERROR] symbol: class DynamoDBTable
[ERROR] /workspace/src/main/java/com/example/model/Account.java:[4,54] package org.springframework.data.dynamodb.core.mapping does not exist
[ERROR] /workspace/src/main/java/com/example/model/Account.java:[5,54] package org.springframework.data.dynamodb.core.mapping does not exist
[ERROR] /workspace/src/main/java/com/example/model/Account.java:[7,2] cannot find symbol
[ERROR] symbol: class DynamoDBTable
[ERROR] /workspace/src/main/java/com/example/model/User.java:[4,54] package org.springframework.data.dynamodb.core.mapping does not exist
[ERROR] /workspace/src/main/java/com/example/model/User.java:[5,54] package org.springframework.data.dynamodb.core.mapping does not exist
[ERROR] /workspace/src/main/java/com/example/model/User.java:[7,2] cannot find symbol
[ERROR] symbol: class DynamoDBTable
[ERROR] /workspace/src/main/java/com/example/model/Transaction.java:[10,6] cannot find symbol
[ERROR] symbol: class DynamoDBHashKey
[ERROR] location: class com.example.model.Transaction
[ERROR] /workspace/src/main/java/com/example/model/Account.java:[10,6] cannot find symbol
[ERROR] symbol: class DynamoDBHashKey
[ERROR] location: class com.example.model.Account
[ERROR] /workspace/src/main/java/com/example/model/User.java:[10,6] cannot find symbol
[ERROR] symbol: class DynamoDBHashKey
[ERROR] location: class com.example.model.User
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>2.7.18</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>1.12.714</version>
</dependency>
<dependency>
<groupId>com.github.derjust</groupId>
<artifactId>spring-data-dynamodb</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>
来自
import org.springframework.data.dynamodb.core.mapping.DynamoDBHashKey;
import org.springframework.data.dynamodb.core.mapping.DynamoDBTable;
致
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;
根据错误信息 [ERROR] /workspace/src/main/java/com/example/model/Transaction.java:[7,2] 找不到符号 符号:DynamoDBTable 类
缺少 DynamoDBTable 类。
import org.springframework.data.dynamodb.core.mapping.DynamoDBTable;
根据您的代码,您正在使用 org.springframework.data.dynamodb.core.mapping.DynamoDBTable。
org.springframework.data.dynamodb
但是,在网上找不到
org.springframework.data.dynamodb
包。
可以在 https://spring.io/projects/spring-data -> 社区模块 -> Spring Data DynamoDB - 适用于 DynamoDB 的 Spring Data 模块找到。 请注意,这是社区模块,链接指向 https://github.com/boostchicken/spring-data-dynamodb
也就是说Spring官方不存在
org.springframework.data.dynamodb.core.mapping.DynamoDBTable
的存在。
software.amazon.awssdk:dynamodb:2.16.32 - dynamodb-2.16.32.jar 2021 年 3 月 31 日
com.github.derjust:spring-data-dynamodb:5.1.0 - spring-data-dynamodb-5.1.0.jar 2019 年 1 月 28 日
解压罐子,
DynamoDBHashKey.class
,找不到匹配的。DynamoDBHashKey
,仅找到:org/socialsignin/spring/data/dynamodb/repository/support/DynamoDBHashKeyExtractingEntityMetadata.class
失败。
找到 https://www.baeldung.com/spring-data-dynamodb(使用 Spring Data 的 Spring Boot 应用程序中的 DynamoDB)
找到
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>1.12.714</version>
</dependency>
下载 jar:aws-java-sdk-dynamodb-1.12.714.jar。
解压罐子。
搜索
DynamoDBHashKey.class
和DynamoDBTable.class
在以下位置找到它:
com/amazonaws/services/dynamodbv2/datamodeling/DynamoDBHashKey.class
com/amazonaws/services/dynamodbv2/datamodeling/DynamoDBTable.class
您的代码需要修改:
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;