我的具体问题是正在实例化的 bean 正在错误的位置查找文件。在我的应用程序的配置中,该值从未定义过,并且是 bean 的默认值。
这是我的应用程序配置:
@Configuration
public class AWSConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(AWSConfig.class);
// base sqs endpoint url is injected from application.properties
@Bean(name="awsClient")
@Primary
public AmazonSQSAsyncClient amazonSQSClient() {
LOGGER.info("Instantiating AmazonSQSAsyncClient Bean");
AmazonSQSAsyncClient awsSQSAsyncClient
= new AmazonSQSAsyncClient();
return awsSQSAsyncClient;
}
}
这是测试类:
@RunWith(SpringRunner.class)
@SpringBootTest
@WebAppConfiguration
public class SqsQueueDaoIT {
private static final Logger LOGGER = LoggerFactory.getLogger(SqsQueueDaoIT.class);
@Autowired
SqsQueueDao sqsQueueDao;
@Autowired
AmazonSQSAsync amazonSQSAsync;
final String TEST_QUEUE_NAME = "queueName";
final String TEST_QUEUE_ENDPOINT = "sqs.us-east-1.amazonaws.com/123123123123123/";
final String TEST_ACTION = "validate";
final String TEST_BODY = "new body";
@Test
public void helloTest() {
sqsQueueDao.send(TEST_QUEUE_NAME, TEST_ACTION, TEST_BODY);
String body = receiveMessageResult().getMessages().get(0).getBody();
assertTrue(body.contains("action"));
assertTrue(body.contains("source_system_id"));
assertTrue(body.contains(TEST_ACTION));
assertTrue(body.contains(TEST_BODY));
}
private ReceiveMessageResult receiveMessageResult() {
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(TEST_QUEUE_ENDPOINT + TEST_QUEUE_NAME);
receiveMessageRequest.putCustomQueryParameter("QueueName", TEST_QUEUE_NAME);
receiveMessageRequest.putCustomQueryParameter("QueueUrl", TEST_QUEUE_ENDPOINT);
return amazonSQSAsync.receiveMessage(receiveMessageRequest);
}
}
阻止我运行测试的错误是:
Failed to instantiate [com.amazonaws.auth.profile.ProfilesConfigFile]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: AWS credential profiles file not found in the given path: /Users/user.name/Code/fullfillment/default
bean 的默认位置是不同的位置,我没有设置它来查看它的位置。
- 如果您对 AWS w/Spring 有特定的了解,是否会发生一些常见的事情?
- 你如何简单地复制运行应用程序,就像 spring-boot:run 为了运行测试所做的那样?