简体   繁体   English

由于缺少 EmbeddedServletContainerFactory bean,Spring Boot 无法启动 EmbeddedWebApplicationContext

[英]Spring Boot Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean

I have a spring boot web application which I'm trying to get running as a standalone application with Tomcat embedded rather than using a container.我有一个 Spring Boot Web 应用程序,我试图将它作为一个独立的应用程序运行,其中嵌入了 Tomcat 而不是使用容器。

I'm developing in IntelliJ, and I've setup a run configuration as Spring Boot and the application is working running from IntelliJ.我正在 IntelliJ 中进行开发,并且已将运行配置设置为 Spring Boot,并且该应用程序正在从 IntelliJ 运行。

I've created an artifact in IntelliJ to create a JAR file and I've set it to include all of the dependencies from Maven.我在 IntelliJ 中创建了一个工件来创建一个 JAR 文件,并将它设置为包含来自 Maven 的所有依赖项。

However, when I run the application I get an error;但是,当我运行应用程序时出现错误;

14:52:19.303 [main] ERROR o.s.boot.SpringApplication - Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) ~[NatLocApp.jar:na]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531) ~[NatLocApp.jar:na]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[NatLocApp.jar:na]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) [NatLocApp.jar:na]
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:347) [NatLocApp.jar:na]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:295) [NatLocApp.jar:na]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1112) [NatLocApp.jar:na]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1101) [NatLocApp.jar:na]
    at com.nationallocums.Application.main(Application.java:13) [NatLocApp.jar:na]
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:183) ~[NatLocApp.jar:na]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:156) ~[NatLocApp.jar:na]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ~[NatLocApp.jar:na]
    ... 8 common frames omitted

From my research I can see this has something to do with Tomcat not being embedded or maybe multiple instanced of Tomcat being included in the final JAR file, but I don't seem to be able to resolve the issue.从我的研究中,我可以看到这与 Tomcat 没有被嵌入或者 Tomcat 的多个实例被包含在最终的 JAR 文件中有关,但我似乎无法解决这个问题。

Here's what my pom.xml file looks like;这是我的 pom.xml 文件的样子;

<dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.37</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.1</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>

        <dependency>
            <groupId>net.sf.opencsv</groupId>
            <artifactId>opencsv</artifactId>
            <version>2.3</version>
        </dependency>

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.4</version>
        </dependency>

        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.9.2</version>
        </dependency>
    </dependencies>

I've tried setting the tomcat dependency as having a scope of 'provided' and removing the scope tag completely, but neither seems to make any difference.我已经尝试将 tomcat 依赖项设置为具有“提供”范围并完全删除范围标记,但两者似乎都没有任何区别。

You should have the spring-boot-maven-plugin in your pom.xml file.你的 pom.xml 文件中应该有 spring-boot-maven-plugin。 And packaging set to jar.并将包装设置为罐子。

Then you can:然后你可以:

$ mvn package
$ java -jar target/mymodule-0.0.1-SNAPSHOT.jar
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

Solution Delete this line:“ <scope>provided</scope>解决方法删除这一行:“ <scope>provided</scope>

The possible values for the scope property are outlined here . 此处概述了 scope 属性的可能值。 The provided scope is described as the following:提供的范围描述如下:

This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime .这很像 compile,但表明您希望 JDK 或容器在运行时提供依赖项 For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes.例如,在为 Java Enterprise Edition 构建 Web 应用程序时,您可以将对 Servlet API 和相关 Java EE API 的依赖项设置为提供的范围,因为 Web 容器提供这些类。 This scope is only available on the compilation and test classpath, and is not transitive.此范围仅在编译和测试类路径上可用,并且不可传递。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Boot:由于缺少 EmbeddedServletContainerFactory bean 无法启动 EmbeddedWebApplicationContext - Spring Boot: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean Spring boot -- 由于缺少 EmbeddedServletContainerFactory bean 无法启动 EmbeddedWebApplicationContext - Spring boot -- Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean 由于缺少EmbeddedServletContainerFactory bean,无法启动EmbeddedWebApplicationContext - Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean 带Web套接字的Spring Boot微服务:由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext - Spring Boot Microservice w/ Web Sockets: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean 错误:由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext - Error : Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean Springboot可执行JAR-错误:由于缺少EmbeddedServletContainerFactory bean而无法启动EmbeddedWebApplicationContext - Springboot Executable JAR - Error: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean Spring Boot异常-由于缺少EmbeddedServletContainerFactory bean - Spring boot exception - due to missing EmbeddedServletContainerFactory bean 由于缺少EmbeddedServletContainerFactory bean,Spring Application无法启动 - Spring Application doesn't start due to missing EmbeddedServletContainerFactory bean Jetty 9 + Spring 引导 - 由于缺少 ServletWebServerFactory bean,无法启动 ServletWebServerApplicationContext - Jetty 9 + Spring Boot - Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean spring-boot web 应用程序启动失败:由于缺少 ServletWebServerFactory bean,无法启动 ServletWebServerApplicationContext - spring-boot web app fails to start : Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM