about spring boot how to disable web environment correctly : <p>Spring boot non-web application, when start it has below error</p>

<pre><code>Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:185) ~[spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
</code></pre>

<p>Then I tried below manner </p>

<pre><code>new SpringApplication().setWebEnvironment(false);
</code></pre>

<p>then start it still have above error.</p>

<p>Then tried </p>

<pre><code>@SpringBootApplication(exclude={SpringDataWebAutoConfiguration.class})
</code></pre>

<p>but still have the same error.</p>

<p>At last I tried add below configuration in <code>application.properties</code></p>

<pre><code>spring.main.web-environment=false
</code></pre>

<p>this time it works.</p>

<p>Why the first two manner cannot work?</p>
