title: Java spring controller is not being mapped
body: <p>I have a spring web application, which has few controllers. My problem is that while trying to redeploy .war to tomcat (or simply restarting application) controllers aren't being mapped from the first try. I have to redeploy app or restart again until they are finally mapped...I have no idea why this is happening.</p>
  
  <p>One of my controllers:</p>
  
  <pre><code>@RestController
  @RequestMapping("kt")
  public class KTIntegrationController {
  
      @Autowired
      KtImportService importService;
  
      @ExceptionHandler(ItemNotFoundException.class)
      @ResponseStatus(value= HttpStatus.NOT_FOUND)
      public RestError handleNotFoundException(ItemNotFoundException e) {
          return new RestError(404, "NOT FOUND", e.getMessage());
      }
  
      @RequestMapping(value="import/to-db", method=RequestMethod.POST)
      public RestResponse&lt;List&lt;String&gt;&gt; loadToDB(@RequestParam("initiator") String initiator,
                              @RequestParam("process") String pid,
                              @RequestParam("category") String institution) throws KtImportException {
          return new RestResponse&lt;List&lt;String&gt;&gt;(importService.loadToDB(initiator,pid,institution));
      }
  
  }
  </code></pre>
  
  <p>Tomcat log (when controller was not mapped):</p>
  
  <pre><code>...
  ...
  [12:47:40.887] INFO  o.s.w.s.m.m.a.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@bf5b3f: startup date [Thu Aug 27 12:47:23 EEST 2015]; root of context hierarchy
  [12:47:41.107] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity&lt;java.util.Map&lt;java.lang.String, java.lang.Object&gt;&gt; org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
  [12:47:41.108] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[text/html],custom=[]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
  [12:47:41.173] INFO  o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  [12:47:41.173] INFO  o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  [12:47:41.291] INFO  o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  [12:47:41.895] INFO  o.s.j.e.a.AnnotationMBeanExporter - Registering beans for JMX exposure on startup
  [12:47:41.922] INFO  o.s.boot.SpringApplication - Started application in 19.463 seconds (JVM running for 547.311)
  ...
  ...
  </code></pre>
  
  <p>Tomcat log (when controller was mapped):</p>
  
  <pre><code>...
  ...
  [11:27:39.426] INFO  o.s.w.s.m.m.a.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@1722a662: startup date [Thu Aug 27 11:27:28 EEST 2015]; root of context hierarchy
  [11:27:39.577] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/kt/import/to-db],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public com.gerasolutions.rest.RestResponse&lt;java.util.List&lt;java.lang.String&gt;&gt; com.gera.integration.rc.rest.controller.KTIntegrationController.loadToDB(java.lang.String,java.lang.String,java.lang.String) throws com.gera.integration.rc.core.domain.KtImportException
  ...
  ...
  [11:27:39.586] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity&lt;java.util.Map&lt;java.lang.String, java.lang.Object&gt;&gt; org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
  [11:27:39.586] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[text/html],custom=[]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
  [11:27:39.634] INFO  o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  [11:27:39.635] INFO  o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  [11:27:39.706] INFO  o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  [11:27:40.009] INFO  o.s.j.e.a.AnnotationMBeanExporter - Registering beans for JMX exposure on startup
  [11:27:40.022] INFO  o.s.boot.SpringApplication - Started application in 12.283 seconds (JVM running for 19.89)
  ...
  ...
  </code></pre>
  
  <p>I don't expect to find answer how to fix this here, since this is a pretty confusing bug (well, at least for me), but some ideas or pointers where I could start looking would be most helpeful.</p>
  
  <p>--EDIT--</p>
  
  <p>Project structure:</p>
  
  <pre><code>app
      -&gt; src
          -&gt; main
              -&gt; java
                  -&gt; com.app.a
                      -&gt; c
                          -&gt; config
                              -&gt; Config.class
                      -&gt; r
                          -&gt; controller
                              -&gt; Controller.class
                      Application.class
                      ServletInitialiazer.class
              -&gt; resources
              -&gt; webapp (this is empty)
  </code></pre>
  
  <p>Application.class:</p>
  
  <pre><code>@Configuration
  @ComponentScan(basePackages={"com.app.a.*"})
  @EnableAutoConfiguration
  public class Application {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  }
  </code></pre>
  
  <p>ServletInitializer.class:</p>
  
  <pre><code>public class ServletInitializer extends SpringBootServletInitializer {
  
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
          return application.sources(Application.class);
      }
  
  }
  </code></pre>
  
  <p>Config.class has datasource and other beans defined in it. (shouldn't affect this bug)</p>
  
  <p><strong>--EDIT--</strong></p>
  
  <p>What's more, if I simply boot this application .war from my laptop, using command line: <code>mvn spring-boot:run</code>, everything works, controllers are always being mapped from the first try.</p>