【发布时间】:2020-05-18 15:12:34
【问题描述】:
我正在尝试编写集成测试。我想使用本地堆栈来启动一个模拟 AWS 服务的 docker 容器。
此代码将启动 docker 容器,但不会从我的 spring 应用程序中自动装配类。
@RunWith(LocalstackTestRunner.class)
@LocalstackDockerProperties(services = {"dynamodb","sns"})
@ActiveProfiles("test")
@SpringBootTest(classes = {TestApplication.class})
public class FlowTest {
@Autowired
private PublisherFactory publisherFactory;
@Test
public void publishMessage() {
// publisherFactory is null here
Publisher publisher = publisherFactory.getInstance("test-event");
}
}
此代码将从我的应用程序中自动装配类,但不会启动 Docker 容器
@RunWith(SpringRunner.class)
@LocalstackDockerProperties(services = {"dynamodb","sns"})
@ActiveProfiles("test")
@SpringBootTest(classes = {TestApplication.class})
public class FlowTest {
@Autowired
private PublisherFactory publisherFactory;
@Test
public void publishMessage() {
//publisher not null here but Docker container not running
Publisher publisher = publisherFactory.getInstance("test-event");
}
}
【问题讨论】:
标签: java spring amazon-web-services spring-integration localstack