applicationcontextexception:由于缺少servletwebserverfactory bean,无法启动servletwebserverapplicationcontext

e7arh2l6  于 2021-07-13  发布在  Spark
关注(0)|答案(21)|浏览(385)

我已经使用springboot编写了一个spring批处理应用程序。当我尝试在本地系统上使用命令行和类路径运行该应用程序时,它运行良好。然而,当我试图在linux服务器上运行它时,它给了我以下异常

Unable to start web server; nested exception is
org.springframework.context.ApplicationContextException: 
Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.

下面是我的操作方式:

java -cp jarFileName.jar; lib\* -Dlogging.level.org.springframework=DEBUG -Dspring.profiles.active=dev -Dspring.batch.job.names=abcBatchJob com.aa.bb.StartSpringBatch > somelogs.log
vjrehmav

vjrehmav16#

注解类 public static void main 例如: @SpringBootApplication

efzxgjgh

efzxgjgh17#

在我的例子中,这个问题是在评论springbootstarteweb中排除tomcat依赖项时解决的

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <!-- <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions> -->
    </dependency>
dfty9e19

dfty9e1918#

您可能会在项目中使用此选项:

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

在这种情况下,您还必须添加:

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

神奇的事情发生了:)
ps:这是因为spring在默认情况下使用WebMVC,而不是WebFlux

jmp7cifd

jmp7cifd19#

我的解决方案与严重的依赖性有关。我有:

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

在我的pom中,我不得不对排除项进行注解以使其生效。出于某种原因,它必须寻找这个tomcat包。

bz4sfanl

bz4sfanl20#

解决方案是:
我将下面的属性显式设置为 noneapplication.yml 文件。

spring:
  main:
    web-application-type: none
rlcwz9us

rlcwz9us21#

可能你失踪了 @SpringBootApplication 在你的 Spring 启动课上。

@SpringBootApplication
public class LoginSecurityAppApplication {

    public static void main(String[] args) {
        SpringApplication.run(LoginSecurityAppApplication.class, args);
    }

}

相关问题