title: How to test multiple Spring Boot applications in one test?
body: <p>I have a multi-module Maven project with 2 Spring Boot applications</p>
  
  <p>parent</p>
  
  <ul>
  <li>fooApp </li>
  <li>barApp </li>
  <li>test</li>
  </ul>
  
  <p>How to set up a test where you can load separate spring boot applications, each with its own configuration context, in the same process.</p>
  
  <pre><code>public abstract class AbstractIntegrationTest {//test module
  
      protected FOO foo;
      protected BAR bar;
  
      @RunWith(SpringJUnit4ClassRunner.class)
      @WebAppConfiguration
      @IntegrationTest
      @Transactional
      @SpringApplicationConfiguration(classes = foo.Application.class)
      public class FOO {
          public MockMvc mockMvc;
  
          @Autowired
          public WebApplicationContext wac;
  
          @Before
          public void _0_setup() {
              MockitoAnnotations.initMocks(this);
              mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
              TestCase.assertNotNull(mockMvc);
          }
  
          public void login(String username) {
          }
      }
  
      @RunWith(SpringJUnit4ClassRunner.class)
      @WebAppConfiguration
      @IntegrationTest
      @Transactional
      @SpringApplicationConfiguration(classes = bar.Application.class)
      public class BAR {
  
          @Autowired
          public WebApplicationContext wac;
  
          public MockMvc restMvc;
  
          @Before
          public void _0_setup() {
              MockitoAnnotations.initMocks(this);
              restMvc = MockMvcBuilders.webAppContextSetup(wac).build();
              TestCase.assertNotNull(restMvc);
          }
  
          public void login(String username) {
          }
      }
  
      @Before
      public void _0_setup() {
          foo = new FOO();
          bar = new BAR();
      }
  }
  </code></pre>
  
  <p>And an example of an integration test</p>
  
  <pre><code>public class IntegrationTest extends AbstractIntegrationTest {
  
      @Test
      public void login() {
          foo.login("foologin");
          bar.login("barlogin");
      }
  
  }
  </code></pre>