title: @SpringBootTest for a non-spring-boot application
body: <p>I am creating a non-spring-boot application using spring-rest, spring-data-jpa etc and I would like to do integration testing using spring boot (1.4.1.RELEASE). Note that I don't have a SpringApplication class or @SpringApplication annotation anywhere</p>
  
  <p>On my test class I have</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = MyConfiguration.class)
  public class MyIT { }
  
  @RestController
  public class MyController { }
  </code></pre>
  
  <p>This is starting an embedded tomcat and I can see that my controller is being initialized, however, I get a 404 when calling my service using TestRestTemplate. It appears that DispatcherServlet does not seem to know about my controllers</p>
  
  <p>Also, I had to define a servletContainer bean as follows</p>
  
  <pre><code>@Bean
  public EmbeddedServletContainerFactory servletContainer() {
      TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
      factory.setPort(9000);
      factory.setSessionTimeout(10, TimeUnit.MINUTES);
      return factory;
  }
  </code></pre>
  
  <p>Am I missing any configuration for Spring to have my controllers visible to embedded tomcat? I tried using @EnableAutoConfiguration @ComponentScan on the test class but they don't have any effect. I have wasted two days on this and any hints are greatly appreciated!!</p>
  
  <p>Complete MyIT class</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { TestContextConfiguration.class })
  public class MyIT {
  
  @Value("${local.server.port}")
  private int serverPort;
  
  @Resource
  private TestRestTemplate restTemplate;
  
  @Test
  public void test() throws Exception {
      System.out.println("Port:" + serverPort);
      System.out.println("Hello:" + this.restTemplate.getForEntity("/", String.class));
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Controller class</p>
  
  <pre><code>@RestController
  public class MyController {
  
      @GetMapping("/")
      public String hello() {
          System.out.println("Hello called");
          return "Hello";
      }
  
  }
  </code></pre>
  
  <p>Output of the test</p>
  
  <pre><code>Port:9000
  Hello:&lt;404 Not Found,&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;Apache Tomcat/8.5.5 - Error report&lt;/title&gt;&lt;style type="text/css"&gt;H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}&lt;/style&gt; &lt;/head&gt;&lt;body&gt;&lt;h1&gt;HTTP Status 404 - /&lt;/h1&gt;&lt;div class="line"&gt;&lt;/div&gt;&lt;p&gt;&lt;b&gt;type&lt;/b&gt; Status report&lt;/p&gt;&lt;p&gt;&lt;b&gt;message&lt;/b&gt; &lt;u&gt;/&lt;/u&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;description&lt;/b&gt; &lt;u&gt;The requested resource is not available.&lt;/u&gt;&lt;/p&gt;&lt;hr class="line"&gt;&lt;h3&gt;Apache Tomcat/8.5.5&lt;/h3&gt;&lt;/body&gt;&lt;/html&gt;,{Content-Type=[text/html;charset=utf-8], Content-Language=[en], Content-Length=[992], Date=[Wed, 05 Oct 2016 14:26:46 GMT]}&gt;
  </code></pre>