title: Run Spring-boot's main using IDE
body: <p>I have a spring-boot application that needs to:</p>
  
  <ul>
  <li>Be deployable as a war in a servlet container</li>
  <li>Be runnable via `mvn spring-boot:run``</li>
  </ul>
  
  <p>I'd also like to be able to run this application in my IDE (Eclipse or IntelliJ IDEA Community) by right clicking on the <code>main</code> and running it.</p>
  
  <p>Here are the interesting parts of my pom.xml (Note that I do not inherit from spring-boot-starter-parent pom):</p>
  
  <pre><code>...
          &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;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;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.6&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;${spring.boot.version}&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;repackage&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  </code></pre>
  
  <p>Here's my <code>SpringBootServletInitializer</code>:</p>
  
  <pre><code>@Configuration
  @EnableAutoConfiguration
  @ComponentScan("com.company.theproject")
  public class Application extends SpringBootServletInitializer
  {
      private static final Logger logger = LoggerFactory.getLogger(Application.class);
  
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
      {
          return application.sources(Application.class);
      }
  
      public static void main(String[] args)
      {
          SpringApplication.run(Application.class, args);
      }
  }
  </code></pre>
  
  <p>When running the main inside an IDE I get the following error:</p>
  
  <pre><code>org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:183) ~[spring-boot-1.2.3.RELEASE.jar:1.2.3.RELEASE]
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:156) ~[spring-boot-1.2.3.RELEASE.jar:1.2.3.RELEASE]
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ~[spring-boot-1.2.3.RELEASE.jar:1.2.3.RELEASE]
      ... 12 common frames omitted
  </code></pre>
  
  <p>Seems like <code>mvn spring-boot:run</code> does some more magic that does not happen when running the <code>main</code> directly.</p>
  
  <p>Removing the <code>provided</code> scope from the <code>spring-boot-starter-tomcat</code> dependency fixes this issue but causes trouble when the war is run inside a servlet container.</p>
  
  <p>Right now the only "fix" I've found is to run <code>mvn spring-boot:run</code> within IntelliJ IDEA instead of running the main directly. While this is an acceptable workaround, I'd still like to know why this doesn't work and if it can be fixed.</p>