簡體   English   中英

在 spring 引導中將數據放入發電機數據庫表時出現 Unmarshall 異常

[英]Getting Unmarshall exception while putting data in dynamo db table in spring boot

我正在嘗試將 dynamo db 集成到我的 spring 引導應用程序中 我一直在關注這個 [link][1] 以將 dynamo db 實現到我的 spring 引導應用程序中,每當我嘗試放入我的表時,我都會收到此錯誤“無法解組提供的解組器的異常響應“。我已經使用 aws 控制台手動創建了我的 dynamo db 表我在下面提到了我的代碼

Controller

    @RestController
public class EmployeeController {
    @Autowired
    private EmployeeRepository employeeRepository;

    @PostMapping("/emp")
    public String data(Employee employee){
        return employeeRepository.updateData(employee);
    }

服務

@Service
public class EmployeeRepository {
    public String updateData(Employee employee) {

        AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build();

        DynamoDB dynamoDB = new DynamoDB(client);

        Table table = dynamoDB.getTable("employee");

        Item item = new Item()
                .withPrimaryKey("employeeId", "1")
                .withString("firstName", "micky")
                .withString("lastName", "mouse")
                .withString("emailId", "mic@gmail.com");
         table.putItem(item);
        return "OK";
    }
}

DynamoDB 配置

@Configuration
public class DynamoDBConfiguration {
    @Bean
    public DynamoDBMapper dynamoDBMapper(){
        return new DynamoDBMapper(buildAmazonDynamoDb());
    }

    private AmazonDynamoDB buildAmazonDynamoDb() {
        return AmazonDynamoDBClientBuilder
                .standard()
                .withEndpointConfiguration(
                new AwsClientBuilder.EndpointConfiguration("dyno-config")
                )
                .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(
                        "accessKey","SecretKey"))).build();
    }
}

實體

@Data
@AllArgsConstructor
@NoArgsConstructor
@DynamoDBTable(tableName="employee")
public class Employee {
    public String employeeId;
    public String firstName;
    public String lastName;
    public String emailId;
}

員工實體中提到的值與 mu dynamoDB 實體同名。誰能幫我找出我的代碼有什么問題 [1]: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/JavaDocumentAPIItemCRUD .html

您正在使用舊的 V1 代碼。 這不是最佳做法。 在使用DynamoDbClient的同一指南中查看此部分。

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/example_cross_DynamoDBDataTracker_section.html

This link uses the AWS SDK for Java V2 and shows you how to successfully develop a Spring REST API that queries Amazon DynamoDB data.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM