gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 08:32:46 27 4
gpt4 key购买 nike

我有一个 spring boot web 应用程序,我试图让它作为一个独立的应用程序运行,嵌入了 Tomcat 而不是使用容器。

我在 IntelliJ 中开发,我已经将运行配置设置为 Spring Boot,应用程序正在从 IntelliJ 运行。

我在 IntelliJ 中创建了一个工件来创建 JAR 文件,并将其设置为包含来自 Maven 的所有依赖项。

但是,当我运行该应用程序时出现错误;

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

根据我的研究,我可以看出这与 Tomcat 未被嵌入或 Tomcat 的多个实例包含在最终 JAR 文件中有关,但我似乎无法解决该问题。

这是我的 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>

我已经尝试将 tomcat 依赖项设置为具有“提供”的范围并完全删除范围标记,但两者似乎都没有任何区别。

最佳答案

您的 pom.xml 文件中应该有 spring-boot-maven-plugin。并将包装设置为jar。

然后你可以:

$ mvn package
$ java -jar target/mymodule-0.0.1-SNAPSHOT.jar

关于java - 由于缺少 EmbeddedServletContainerFactory bean,Spring Boot 无法启动 EmbeddedWebApplicationContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39898009/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com