title: Spring MVC with Spring Boot doesn't work with the Tomcat server of Eclipse
body: <p>I tried to follow Spring Getting Started Guide for "Serving Web Content with Spring MVC" which uses Spring Boot and Gradle in addition to Maven.
  I installed Gradle plugins to Eclipse.</p>
  
  <p>I want to run the application using the Tomcat server in Eclipse because of that I also followed "Converting a Spring Boot JAR Application to a WAR" guide and changed the "build.gradle" file as mentioned in the guide. Basically, I added lines "apply plugin: 'eclipse-wtp'", "apply plugin: 'war'", configurations {providedRuntime}, and providedRuntime("org.springframework.boot:spring-boot-starter-tomcat"); and changed jar settings to war settings. Here is the build.gradle file:</p>
  
  <pre><code>buildscript {
  repositories {
      maven { url "http://repo.spring.io/libs-milestone" }
      mavenLocal()
  }
  dependencies {
      classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.2.RELEASE")
  }
  }
  
  apply plugin: 'java'
  apply plugin: 'eclipse-wtp'
  apply plugin: 'idea'
  apply plugin: 'spring-boot'
  apply plugin: 'war'
  
  eclipse.project {
    natures 'org.springsource.ide.eclipse.gradle.core.nature'
  }
  
  war {
      baseName = 'gs-serving-web-content'
      version =  '0.1.0'
  }
  
  repositories {
      mavenCentral()
      maven { url "http://repo.spring.io/libs-milestone" }
  }
  
  configurations {
      providedRuntime
  }
  
  dependencies {
      compile("org.springframework.boot:spring-boot-starter-thymeleaf")
      testCompile("junit:junit")
      providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
  }
  
  task wrapper(type: Wrapper) {
      gradleVersion = '1.11'
  }
  </code></pre>
  
  <p>I also added HelloWebXml class as they mention. Here is the class:</p>
  
  <pre><code>package hello;
  
  import org.springframework.boot.builder.SpringApplicationBuilder;
  import org.springframework.boot.context.web.SpringBootServletInitializer;
  
  public class HelloWebXml extends SpringBootServletInitializer {
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
          return application.sources(Application.class);
      }
  }
  </code></pre>
  
  <p>In addition to these I needed to change pom.xml a little because it was complaining about Java SE 7 features. Added the lines below to the pom.xml:</p>
  
  <pre><code>&lt;plugin&gt;
      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
      &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
          &lt;configuration&gt;
              &lt;source&gt;1.7&lt;/source&gt;
              &lt;target&gt;1.7&lt;/target&gt;
              &lt;showWarnings&gt;true&lt;/showWarnings&gt;
              &lt;compilerVersion&gt;1.7&lt;/compilerVersion&gt;
              &lt;fork&gt;true&lt;/fork&gt;
          &lt;/configuration&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>The rest is the same as the getting started guide.</p>
  
  <p>For building, I run</p>
  
  <pre><code>gradlew eclipseWtp
  gradlew clean build
  </code></pre>
  
  <p>commands. After this the war file is created in build/libs folder of the project. If I copy the war file to my local Tomcat server and start the server, everything works as expected.</p>
  
  <p>If I drag the project to the Tomcat server under the Servers tab (which is created using the same local Tomcat) and run the server, a ClassCastException is thrown with the complaint:
  "<strong>Cannot cast org.springframework.web.SpringServletContainerInitializer to javax.servlet.ServletContainerInitializer</strong>".</p>
  
  <p>I checked the folder structure of the project in both of the deployment locations.
  In the local (non-Eclipse) deployment location, after the server starts a folder with the name of the war file is created as expected. In the WEB-INF folder, there is a <strong>lib-provided</strong> directory. I checked the deployment location of the Tomcat of Eclipse, it didn't include a directory named lib-provided. I guess the problem is about this directory not being created but I couldn't find a solution.</p>
  
  <p>I was already using Spring MVC, and I know how to create MVC projects with web.xml but I am new to Spring Boot. The Tomcat server of Eclipse runs my previous Spring MVC projects fine. So the problem is about the Spring Boot project.</p>
  
  <p>I checked several related questions but they were not the same one as mine. I couldn't find a solution to my problem.</p>
  
  <p>What am I missing here?</p>
  
  <p>Thanks in advance.</p>