我有几个spring引导应用程序的实例,这些应用程序与DB并行执行一些工作。每个实例都在单独的JVM中运行。
这是一种用Java编写测试的方法,用于在一个JVM上测试吗?如下所示:
每个实例都有自己的上下文和类路径。
我认为我可以通过一些shell脚本场景来实现这一点,但是我想用Java来实现它。
这里最好的方法是什么?
发布于 2017-12-18 11:08:28
您可以使用不同的端口多次运行它们。
我也做过类似的事
@RunWith(SpringJUnit4ClassRunner.class)
public class ServicesIntegrationTest {
private RestTemplate restTemplate = new RestTemplate();
@Test
public void runTest() throws Exception {
SpringApplicationBuilder uws = new SpringApplicationBuilder(UserWebApplication.class)
.properties("server.port=8081",
"server.contextPath=/UserService",
"SOA.ControllerFactory.enforceProxyCreation=true");
uws.run();
SpringApplicationBuilder pws = new SpringApplicationBuilder(ProjectWebApplication.class)
.properties("server.port=8082",
"server.contextPath=/ProjectService",
"SOA.ControllerFactory.enforceProxyCreation=true");
pws.run();
String url = "http://localhost:8081/UserService/users";
ResponseEntity<SimplePage<UserDTO>> response = restTemplate.exchange(
url,
HttpMethod.GET,
null,
new ParameterizedTypeReference<SimplePage<UserDTO>>() {
});这里是来源。
https://stackoverflow.com/questions/47866954
复制相似问题