Vij*_*tia 25 spring spring-batch spring-boot
我使用Spring启动编写了一个Spring批处理应用程序.当我尝试在本地系统上使用命令行和类路径运行该应用程序时,它运行正常.但是,当我试图在Linux服务器上运行它时,它给了我以下异常
Unable to start web server; nested exception is
org.springframework.context.ApplicationContextException:
Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
Run Code Online (Sandbox Code Playgroud)
以下是我运行它的方式:
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
Run Code Online (Sandbox Code Playgroud)
saj*_*jib 38
web application type
在属性文件中禁用:在application.properties
:
spring.main.web-application-type=none
Run Code Online (Sandbox Code Playgroud)
如果你使用application.yml
然后添加:
spring:
main:
web-application-type: none
Run Code Online (Sandbox Code Playgroud)
*SpringBootServletInitializer*
在主类中扩展.@SpringBootApplication
public class YourAppliationName extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(YourAppliationName.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
Spe*_*ton 16
我的解决方案与不良依赖有关。我有:
<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>
Run Code Online (Sandbox Code Playgroud)
在我的 pom 中,我不得不注释掉排除以使其正常工作。出于某种原因,它必须寻找这个 tomcat 包。
小智 14
可能您缺少@SpringBootApplication
Spring Boot入门类。
@SpringBootApplication
public class LoginSecurityAppApplication {
public static void main(String[] args) {
SpringApplication.run(LoginSecurityAppApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
Vij*_*tia 13
解决方案是:
我明确下面的属性设置为none
在application.yml
文件中.
spring:
main:
web-application-type: none
Run Code Online (Sandbox Code Playgroud)
adr*_*rhc 10
您可能会在您的项目中使用它:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,您还必须添加:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
奇迹发生了:)
PS:那是因为当两者都可用时,Spring 将默认使用web-MVC而不是web-flux
在我的情况下,问题解决了从 spring-boot-starte-web 中注释 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>
Run Code Online (Sandbox Code Playgroud)
添加以下 bean 对我有用。
@Bean
public ServletWebServerFactory servletWebServerFactory() {
return new TomcatServletWebServerFactory();
}
Run Code Online (Sandbox Code Playgroud)
我在SpringApplication.run(MyApplication.class, args);
没有@SpringBootApplication
注释的情况下运行非 web spring 应用程序。
要将 Spring boot wen 应用程序转换为独立应用程序:
Run Code Online (Sandbox Code Playgroud)spring.main.web-application-type=none
Run Code Online (Sandbox Code Playgroud)ApplicationContext ctx = new SpringApplicationBuilder(MigrationRunner.class) .web(WebApplicationType.NONE).run(args);
使用应用程序上下文,您可以获得您的bean:
myBean bean = (MyBean) ctx.getBean("myBean", MyBean.class); bean.call_a_method(..);
归档时间: |
|
查看次数: |
63613 次 |
最近记录: |