我希望从Dynamo数据库表中获取所有记录,并将它们映射到POJO数组中; POJO很简单,已经注释了.
DynamoDBMapper似乎是一个对象,它将执行获取以获取记录并将其反序列化为我的POJO.也许使用PaginatedScanList()遍历整个表.
Mapper的Scan()和PaginatedScanList()方法都需要DynamoDBScanExpression参数.DynamoDBScanExpression将用于选择表中的所有记录?
我们有一个暴露 REST api 的 Spring Boot 1.4 Web 应用程序,我们想要运行一些集成测试。
在我们的测试中,我们让 Spring Boot 在本地启动 Web 应用程序,然后我们对 api 进行一些调用。
如果我们简单地运行 Web 应用程序本身并点击端点,我们会得到200/OK响应,这是预期的。然而,运行测试,我们得到了401/Unauthorized服务器响应。
我应该在哪里查看可能导致授权错误的原因?
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {Application.class}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class DemoApplication3IT {
private final Logger log = LoggerFactory.getLogger(DemoApplication3IT.class);
@Autowired
private TestRestTemplate restTemplate;
@Test
public void getFunky() throws IOException {
ResponseEntity<String> response =
this.restTemplate.getForEntity("http://localhost:8080/api/funky", String.class);
log.info("TestRestTemplate response Code: " + response.getStatusCode());
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); // Expected :200, Actual :401
}
}
Run Code Online (Sandbox Code Playgroud)
奇怪的是,使用浏览器访问端点工作正常,但集成测试失败。
尽管文档表明不需要有效凭证,但 DynamoDBLocal 仍拒绝我的凭证:
适用于 DynamoDB 的 AWS 开发工具包要求您的应用程序配置指定访问密钥值和 AWS 区域值...这些值不必是有效的 AWS 值才能在本地运行。
在这种情况下,我将我的凭据设置~/.aws/credentials为:
[default]
aws_access_key_id = BogusAwsAccessKeyId
aws_secret_access_key = BogusAwsSecretAccessKey
Run Code Online (Sandbox Code Playgroud)
使用以下命令运行 DynamoDBLocal:
java -Djava.library.path=./DynamoDBLoc_lib -jar DynamoDBLocal.jar
Run Code Online (Sandbox Code Playgroud)
通过点击http://localhost:8000/shell/检查它是否正常工作
然后运行我的测试 Java 应用程序:
DefaultAWSCredentialsProviderChain credentialProvider = new DefaultAWSCredentialsProviderChain();
AWSCredentials awsCredentials = credentialProvider.getCredentials();
log.info("creds \"{}\", \"{}\"", awsCredentials.getAWSAccessKeyId(), awsCredentials.getAWSSecretKey());
AmazonDynamoDBClient client = new AmazonDynamoDBClient(credentialProvider);
client.withEndpoint("http://localhost:8000");
client.withRegion(Regions.US_WEST_2);
dynamoDB = new DynamoDB(client);
try {
TableCollection<ListTablesResult> tables = dynamoDB.listTables();
while (tables.iterator().hasNext()) { // <-- exception thrown here
log.info(tables.iterator().next().getTableName());
}
} catch (Exception e) …Run Code Online (Sandbox Code Playgroud)