Spring boot deployed on tomcat won't start
<p>I have a working Spring application that contains a embedded Tomcat. As a executable war, it works fine. As I'm going to use AngularJ for the front end, it isn't very practical to have the Spring project in an executable jar, as I will do debugging in the browser and want to be able to quickly edit the js source files. If they are saved in an archive, this is annoying.</p>

<p>That's why I want to make it deployable, so it would get unpacked on a tomcat. It seems to be that easy, but I can't get it to work.</p>

<p>The context always gets loaded twice apparently. Because of that first I get an exception of the repository (<code>@Repository</code>) I use (already blocked) and another exception from spring "Cannot initialize context because there is already a root application context present".</p>

<p>I confused as I already read, that is quite normal that Spring creates 2 contexts, especially with MVC. But why the exceptions then?</p>

<p>My SpringApp class looks like this</p>

<pre><code>@EnableWebMvc
@ComponentScan
@EnableAutoConfiguration
public class LAuthServerApplication extends WebMvcConfigurerAdapter {

    @Autowired
    Environment env;

    public static void main(String[] args) {
    System.out.println("#################### Startup parameters ##############");
    for (String s : args) {
        System.out.println("Parameter: " + s);
    }
    System.out.println("######################################################");
    SpringApplication.run(LAuthServerApplication.class, args);
    }

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
    configurer.enable();
    }

    @Bean
    public InternalResourceViewResolver viewResolver() {
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setPrefix("/WEB-INF/pages/");
    viewResolver.setSuffix(".jsp");
    return viewResolver;
    }
</code></pre>

<p>To make it deployable I added this class to my project:</p>

<pre><code>@Configuration
public class AppServletInitializer extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
}
</code></pre>

<p>POM:</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;ch.comlab.comweb&lt;/groupId&gt;
    &lt;artifactId&gt;LAuth&lt;/artifactId&gt;
    &lt;version&gt;1.0.0&lt;/version&gt;
    &lt;packaging&gt;war&lt;/packaging&gt;
    &lt;properties&gt;
    &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
    &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
    &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;

    &lt;/properties&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.5.RELEASE&lt;/version&gt;
    &lt;/parent&gt;

    &lt;dependencies&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;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.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.security&lt;/groupId&gt;
        &lt;artifactId&gt;spring-security-web&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
        &lt;artifactId&gt;spring-security-config&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;ch.comlab.comweb&lt;/groupId&gt;
        &lt;artifactId&gt;Infrastructure&lt;/artifactId&gt;
        &lt;version&gt;1.2.6&lt;/version&gt;
    &lt;/dependency&gt;

    &lt;/dependencies&gt;
    &lt;build&gt;
    &lt;plugins&gt;
        &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.6&lt;/version&gt;
        &lt;configuration&gt;
            &lt;webResources&gt;
            &lt;resource&gt;
                &lt;directory&gt;src/main/webapp&lt;/directory&gt;
                &lt;filtering&gt;true&lt;/filtering&gt;
            &lt;/resource&gt; 
            &lt;/webResources&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;configuration&gt;
            &lt;resources&gt;
            &lt;resource&gt;
                &lt;filtering&gt;true&lt;/filtering&gt;
                &lt;directory&gt;src/main/resources/&lt;/directory&gt;
            &lt;/resource&gt;
            &lt;/resources&gt;
        &lt;/configuration&gt;
        &lt;/plugin&gt;
    &lt;/plugins&gt;
    &lt;/build&gt;
    &lt;repositories&gt;
    &lt;repository&gt;
        &lt;id&gt;spring-releases&lt;/id&gt;
        &lt;url&gt;https://repo.spring.io/libs-release&lt;/url&gt;
    &lt;/repository&gt;
    &lt;/repositories&gt;
    &lt;pluginRepositories&gt;
    &lt;pluginRepository&gt;
        &lt;id&gt;spring-releases&lt;/id&gt;
        &lt;url&gt;https://repo.spring.io/libs-release&lt;/url&gt;
    &lt;/pluginRepository&gt;
    &lt;/pluginRepositories&gt;
    &lt;name&gt;LAuth&lt;/name&gt;
&lt;/project&gt;
</code></pre>