title: spring-boot w/ embedded tomcat doesn't dispatch requests to controller
body: <p>I have an application using spring-boot and an embedded Tomcat container.</p>
  
  <p>As far as I can tell, my code is the same as the spring-boot <a href="https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-tomcat" rel="noreferrer">sample project</a>. However, when I run my test, I get a 404 instead of a 200 (in the case where I try to post instead of get I receive a 405, which is consistent with Tomcat being incorrectly setup):</p>
  
  <pre><code>Failed tests:
  UserControllerTest.testMethod:45 Status expected:&lt;200&gt; but was:&lt;404&gt;
  </code></pre>
  
  <p>My Java-based configuration (some configuration classes omitted):</p>
  
  <pre><code>@Configuration
  @ComponentScan
  @EnableAutoConfiguration
  @Import({ ServiceConfig.class, DefaultRepositoryConfig.class })
  public class ApplicationConfig {
  
      private static Log logger = LogFactory.getLog(ApplicationConfig.class);
  
      public static void main(String[] args) {
          SpringApplication.run(ApplicationConfig.class);
      }
  
      @Bean
      protected ServletContextListener listener() {
          return new ServletContextListener() {
              @Override
              public void contextInitialized(ServletContextEvent sce) {
                  logger.info("ServletContext initialized");
              }
  
              @Override
              public void contextDestroyed(ServletContextEvent sce) {
                  logger.info("ServletContext destroyed");
              }
          };
      }
  }
  </code></pre>
  
  <p>UserController.java:</p>
  
  <pre><code>@RestController
  @RequestMapping("/")
  public class UserController {
  
      @Autowired
      UserService userService;
  
      @RequestMapping(method = RequestMethod.GET)
      public ResponseEntity&lt;String&gt; testMethod() {
          return new ResponseEntity&lt;&gt;("Success!", HttpStatus.OK);
      }
  }
  </code></pre>
  
  <p>UserControllerTest.java:</p>
  
  <pre><code>RunWith(SpringJUnit4ClassRunner.class)
  @WebAppConfiguration
  @ContextConfiguration(classes = {ApplicationConfig.class})
  public class UserControllerTest {
      @Autowired
      private WebApplicationContext webApplicationContext;
      private MockMvc mockMvc;
  
      @Before
      public void setUp() throws Exception {
          this.mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext).build();
      }
  
      @Test
      public void testMethod() throws Exception {
          this.mockMvc.perform(get("/")).andExpect(status().isOk());
      }
  }
  </code></pre>
  
  <p>Is there something basic I'm missing? I'm not providing my own Mvc configuration, and I haven't touched the Spring MVC DispatcherServlet, so I assume spring-boot will configure Tomcat automatically.</p>