我使用 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/