title: Unable to start embedded tomcat Spring boot
body: <p>I'm working on Spring Boot Gradle application. My app is throwing error when i try to run it as a war by doing booRun. The error says : Unable to start embedded tomcat.
  The contents of build.gradle file :</p>
  
  <pre><code>    group 'com.example'
      version '1.0-SNAPSHOT'
  
  
  
  bootRepackage {
      mainClass = 'com.ex.MainClass'
  }
  
  
  apply plugin: 'war'
  apply plugin: 'propdeps'
  
  war {
      baseName = 'abc'
      archiveName 'abc.war'
  
  }
  
  repositories{
  //    mavenLocal()
      mavenCentral()
  }
  
  
  dependencies {
  
          compile("org.springframework.boot:spring-boot-starter-web")
          compile("org.springframework.boot:spring-boot-starter-data-jpa")
          compile("io.springfox:springfox-swagger2:2.7.0")
          compile("io.springfox:springfox-swagger-ui:2.7.0")
          compile fileTree(dir:"lib", include:"*.jar")
          compile('org.springframework.boot:spring-boot-starter-mail')
          optional("org.springframework.boot:spring-boot-configuration-processor")
          compile("org.springframework.boot:spring-boot-starter-tomcat")
          compile "io.springfox:springfox-swagger2:2.7.0"
          compile 'io.springfox:springfox-swagger-ui:2.7.0'
          compile("org.springframework.boot:spring-boot-starter-amqp")
      }
  
     compileJava.dependsOn(processResources)
  </code></pre>
  
  <p>The whole stack trace is given below :</p>
  
  <pre><code>org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
      at com.ex.MainClass.main(MainClass.java:38) [main/:na]
  Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
      at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:123) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
      at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.&lt;init&gt;(TomcatEmbeddedServletContainer.java:84) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
      at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:554) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
      at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:179) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
      ... 8 common frames omitted
  Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardServer[-1]]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
      at org.apache.catalina.startup.Tomcat.start(Tomcat.java:344) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
      at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:99) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
      ... 13 common frames omitted
  Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Tomcat]]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
      at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:793) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
      ... 15 common frames omitted
  Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat]]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
      at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
      ... 17 common frames omitted
  Caused by: org.apache.catalina.LifecycleException: A child container failed during start
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:947) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
      at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
      ... 19 common frames omitted
  
  bootRun FAILED
  </code></pre>
  
  <p>EDIT : Adding Main Class definition:</p>
  
  <pre><code>@SpringBootApplication
  @EnableAsync
  @EnableCaching
  @EnableScheduling
  public class MainClass extends SpringBootServletInitializer {
  
      public static final Logger logger = LoggerFactory.getLogger(MainClass.class);
  
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
          return application.sources(MainClass.class);
      }
  
      public static void main(String[] args) {
          SpringApplication.run(MainClass.class, args);
  
      }
  }
  </code></pre>
  
  <p>Can anybody please tell me why my app fails to start on embedded tomcat?</p>
  
  <p>Thanks</p>