2

我正在尝试将 dynamodb 与现有的 java 项目连接,但我发现以下错误:

com.amazonaws.SdkClientException:无法执行 HTTP 请求:连接到 localhost:9000 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] 失败:连接被拒绝:连接

我在 pom.xml 中添加了以下依赖项

       <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>DynamoDBLocal</artifactId>
            <version>[1.11,2.0)</version>
        </dependency>
    <repositories>
        <repository>
            <id>dynamodb-local-oregon</id>
            <url>https://s3.eu-central-1.amazonaws.com/dynamodb-local-frankfurt/release</url>
        </repository>
    </repositories>

DynamoDBProxyServer server = ServerRunner.createServer(new CommandLineInput(new String[] {
                    "-dbPath",
                    System.getProperty("user.dir") + File.separator + "target", "-port", port
            }));
            server.start();
            AmazonDynamoDB dynamodb = AmazonDynamoDBClientBuilder.standard()
                    .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration
                            ("http://localhost:" + port, "us-west-2"))
                    .withCredentials(new AWSStaticCredentialsProvider(new AWSCredentials() {
                        @Override
                        public String getAWSAccessKeyId() {
                            return "foo";
                        }

                        @Override
                        public String getAWSSecretKey() {
                            return "bar";
                        }
                    }))
                    .build();

DynamoDBMapper mapper = new DynamoDBMapper(dynamodb);
        CreateTableRequest req = mapper.generateCreateTableRequest(DocumentDescriptor.class);
        // Table provision throughput is still required since it cannot be specified in your POJO
        req.setProvisionedThroughput(new ProvisionedThroughput(5L, 5L));
        // Fire off the CreateTableRequest using the low-level client
        CreateTableResult result = dynamodb.createTable(req);
        System.out.println(result.toString());

当它执行时CreateTableResult result = dynamodb.createTable(req);,它给了我connection refused error

请帮帮我。提前致谢。

4

0 回答 0