title: Spring Boot Root Controller not working on Tomcat WAR
body: <p>I can't make this line to work on my Spring Boot application deployed as a WAR on a tomcat server.</p>
  
  <pre><code>package com.incidenciasboard;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  
  import com.incidenciasboard.bean.CambioIncidencia;
  import com.incidenciasboard.bean.General;
  import com.incidenciasboard.bean.Incidencia;
  import com.incidenciasboard.dao.CambioIncidenciaDAO;
  import com.incidenciasboard.dao.IncidenciaDAO;
  import com.incidenciasboard.util.Ano;
  import com.incidenciasboard.util.Dia;
  import com.incidenciasboard.util.Log;
  import com.incidenciasboard.util.Mes;
  import com.incidenciasboard.util.ModelFecha;
  import com.incidenciasboard.util.Semana;
  
  @Controller
  public class Stats {
  
      @Autowired
      private CambioIncidenciaDAO cambioDao;
  
      @Autowired
      private IncidenciaDAO dao;
  
      @RequestMapping(value = "/login", method = RequestMethod.GET)
      public String login( Model model) {
          return "login";
      }
  
      @RequestMapping(value = "/", method = RequestMethod.GET)
      public String statcas( Model model) {
          Log.l();
          return "redirect:/stats";
      }
  
      @RequestMapping(value = "/stats", method = RequestMethod.GET)
      public String stats( Model model) {
  
          Iterable&lt;CambioIncidencia&gt; cambios=cambioDao.findAll();
          ModelFecha m=new ModelFecha(0,12,2015);
  
          long total=0;
          int cant=1;
          //Promedio
          for(CambioIncidencia c: cambios){
              if(c.getDespues().equals("Open") &amp;&amp; !c.getDespues().equals("Closed")){
                  long id=c.getTicketid();
                  for(CambioIncidencia cc: cambios){
                      long id2=cc.getTicketid();
  
                      if(id==id2 &amp;&amp; cc.getDespues().equals("Closed")){
                          long cantDias=ModelFecha.diffDias(c.getFecha(), cc.getFecha());
                          cant++;
                          if(cantDias&gt;0){
                              total+=cantDias;
  
                          }
                      }
  
                  }
              }   
          }
  
  
  
          List&lt;Ano&gt; fechas=m.getFechas();
          //Cambios Mensuales
          //Log.log("Cerrados");
          for(CambioIncidencia i:cambios){
              for(Ano ano:fechas){
                  General ga=ano.getGeneral();
                  for(Mes mes:ano.getMeses()){
                      General gm=mes.getGeneral();
                      for(Semana sem:mes.getSemanas()){
                          General gs=sem.getGeneral();
                          for(Dia dia:sem.getDias()){
                              General gd=dia.getGeneral();
                              List&lt;General&gt; ges=new ArrayList&lt;General&gt;();
                              ges.add(ga);
                              ges.add(gm);
                              ges.add(gd);
                              ges.add(gs);
  
                              if(ModelFecha.mismoDia(dia.getFecha(), i.getFecha())){
                                  if(i.getEstado().equals("Open")){
                                      for(General g:ges)g.sAbierto();
                                  }else if(i.getEstado().equals("Closed")){
                                      for(General g:ges)g.sCerrado();
                                      for(General g:ges)g.setCaja(i.getPlata());
                                  }else if(i.getEstado().equals("Critico")){
                                      for(General g:ges)g.sCritico();
                                  }else if(i.getEstado().equals("Listo p/Entregar")){
                                      for(General g:ges)g.sLentregar();
                                  }else if(i.getEstado().equals("Presupuesto Enviado")){
                                      for(General g:ges)g.sPenviado();
                                  }else if(i.getEstado().equals("Esperando Repuestos")){
                                      for(General g:ges)g.sEsperando();
                                  }else if(i.getEstado().equals("Cancelado")){
                                      for(General g:ges)g.sCancelado();
                                  }else if(i.getEstado().equals("In Progress")){
                                      for(General g:ges)g.sProgreso();
                                  }
                              }
                          }
                      }
                  }
              }
          }
  
          General g=new General();
  
          for(Incidencia i:dao.findAll()){
              if(i.getEstado().equals("Open")){
                  g.sAbierto();
              }else if(i.getEstado().equals("Closed")){
                  g.sCerrado();
              }else if(i.getEstado().equals("Critico")){
                  g.sCritico();
              }else if(i.getEstado().equals("Listo p/Entregar")){
                  g.sLentregar();
              }else if(i.getEstado().equals("Presupuesto Enviado")){
                  g.sPenviado();
              }else if(i.getEstado().equals("Esperando Repuestos")){
                  g.sEsperando();
              }else if(i.getEstado().equals("Cancelado")){
                  g.sCancelado();
              }else if(i.getEstado().equals("In Progress")){
                  g.sProgreso();
              }
  
          }
          List&lt;Mes&gt; nubimedia = new ArrayList&lt;Mes&gt;();
          for(Ano a:fechas){
              for(Mes mm:a.getMeses()){
                  nubimedia.add(mm);
              }
          }
          List&lt;Mes&gt; ult4=new ArrayList&lt;Mes&gt;();
          ult4.add(nubimedia.get(nubimedia.size()-5));
          ult4.add(nubimedia.get(nubimedia.size()-4));
          ult4.add(nubimedia.get(nubimedia.size()-3));
          ult4.add(nubimedia.get(nubimedia.size()-2));
          model.addAttribute("quarter",ult4);
  
          General mesactual=nubimedia.get(nubimedia.size()-1).getGeneral();
          General mesanterior=nubimedia.get(nubimedia.size()-2).getGeneral();
  
          General ayer=m.getAyer(fechas).getGeneral();
          General hoy=m.getHoy(fechas).getGeneral();
  
  
          model.addAttribute("hoy",hoy);
          model.addAttribute("ayer",ayer);
          model.addAttribute("mesactual",mesactual);
          model.addAttribute("mesanterior",mesanterior);
          model.addAttribute("prom",(total/cant));
          model.addAttribute("g",g);
          return "index";
      }
  
  
  }
  </code></pre>
  
  <p>I didn't have another option to send the root controller, the index, to "/stats".</p>
  
  <p>I'm using "/..any thing.." it works. But "/" doesn't. You see the redirect I have now, it works when I run spring boot with embedded tomcat but not when I deploy it as a war.</p>
  
  <p>I also made a Log, but it doesn't even print.</p>
  
  <pre><code>@RequestMapping(value = "/", method = RequestMethod.GET)
          public String statcas( Model model) {
              Log.l();
              return "redirect:/stats";
          }
  </code></pre>
  
  <p>Please help!</p>
  
  <p>EDIT 1:</p>
  
  <p>App its called Incendencia, so in url looks like this:</p>
  
  <p>host:8080/Incidencia/</p>
  
  <p>If URL is exactly like that, it doesn't redirect to /stats...</p>
  
  <p>To use the app I must put host:8080/Incidencia/stats</p>
  
  <p>EDIT 2:
  Properties File spring boot:</p>
  
  <pre><code>#REMOTO
  spring.datasource.url = jdbc:mysql://...
  spring.datasource.username = ...
  spring.datasource.password = ...
  
  spring.datasource.testWhileIdle = true
  spring.datasource.validationQuery = SELECT 1
  spring.jpa.show-sql = false
  spring.jpa.hibernate.ddl-auto = update
  spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
  spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
  
  #jsp
  spring.mvc.view.suffix: .jsp
  </code></pre>
  
  <p>And POM File</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.incidenciasboard&lt;/groupId&gt;
      &lt;artifactId&gt;incidenciasboard&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
  
      &lt;name&gt;IncidenciasBoard&lt;/name&gt;
      &lt;description&gt;incidenciasboard&lt;/description&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;1.3.3.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;java.version&gt;1.7&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.tomcat.embed&lt;/groupId&gt;
          &lt;artifactId&gt;tomcat-embed-jasper&lt;/artifactId&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;jstl&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
      &lt;groupId&gt;com.google.guava&lt;/groupId&gt;
      &lt;artifactId&gt;guava&lt;/artifactId&gt;
      &lt;version&gt;19.0&lt;/version&gt;
  &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
          &lt;groupId&gt;org.apache.tomcat.embed&lt;/groupId&gt;
          &lt;artifactId&gt;tomcat-embed-jasper&lt;/artifactId&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;jstl&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.scala-lang&lt;/groupId&gt;
          &lt;artifactId&gt;scala-library&lt;/artifactId&gt;
          &lt;version&gt;2.11.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  
  &lt;/project&gt;
  </code></pre>