您可以使用不同的端口多次運行它們。
我做了類似的
@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>>() {
});
here源東西。
謝謝!有用。實例化Spring引導應用程序的2個副本,並且運行時沒有問題。 – aleksei
你可能知道的一件事。我試圖區分我的正在運行的應用程序的痕跡,我卡在這裏。我試圖添加像這樣的屬性 - 「」logging.pattern.level = App-1「'/'」logging.pattern.level = App-2「」,但它總是顯示第一個'SpringApplicationBuilder.properties' 。你知道它爲什麼會發生,什麼是區分的正確方法? – aleksei
可能是2件事 - 記錄器在配置屬性應用之前被初始化。 OR屬性源的優先級高於SpringApplicationBuilder的屬性。我看到某處用於檢索值但是現在找不到的源的順序。嘗試谷歌。 – StanislavL