spring - 应用程序上下文异常 : Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean

标签 spring spring-boot spring-mvc

我使用 Spring Boot 编写了一个 Spring Batch 应用程序。当我尝试在本地系统上使用命令行和类路径运行该应用程序时,它运行良好。但是,当我尝试在 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

最佳答案

案例一:

@SpringBootApplication 注释在您的 Spring Boot 启动器类中丢失。

案例2:

对于非 Web 应用程序,请在属性文件中禁用 Web 应用程序类型

application.properties中:

spring.main.web-application-type=none

如果你使用 application.yml 然后添加:

  spring:
    main:
      web-application-type: none

对于 Web 应用程序,在主类中扩展 *SpringBootServletInitializer*

@SpringBootApplication
public class YourAppliationName extends SpringBootServletInitializer{
    public static void main(String[] args) {
        SpringApplication.run(YourAppliationName.class, args);
    }
}

案例3:

如果您使用 spring-boot-starter-webflux 则还要添加 spring-boot-starter-web 作为依赖项。

关于spring - 应用程序上下文异常 : Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50231736/

相关文章:

java - 从属性文件加载 JPA 存储库查询

java - Spring 启动: JSON parameter starting with special character

spring-security - 在 Spring Boot 中使用多个 WebSecurityConfigurerAdapter

java - Spring Boot 不从属性文件读取

java - 将Java Map对象转换为Json数组

spring - RedirectAttributes 在 Spring 3.1 中给出 IllegalStateException

java - 如何在 postgres 中没有时区的情况下节省时间。我正在使用 hibernate Spring MVC

java - 如何修复 findbugs "Method accesses list or array with constant index"发现的错误

java - 使用默认模板的 spring mvc 出现 404 错误

java - 无法缓存由 Spring MVC 提供的图像