我正在尝试构建一个独立的Spring Integration应用程序,它具有基于入站RabbitMQ的门控方式.由于应用程序不需要处理HTTP请求,我想让它成为一个可运行的Java项目(可以使用java -jar简单运行).经过Spring Batch Guide example之后我借用了这个想法: –
Make the application executable
Although batch processing can be embedded in web apps and WAR files,
the simpler approach demonstrated below creates a standalone
application. You package everything in a single, executable JAR file,
driven by a good old Java main() method.
问题1
我该如何启动Spring Boot应用程序? Spring Boot Java应用程序必须无休止地运行,直到被中断.
问题2
排除Web项目性质.
目前我正在尝试运气: –
@SpringBootApplication(exclude = { WebMvcAutoConfiguration.class,
EmbeddedServletContainerAutoConfiguration.class,
DispatcherServletAutoConfiguration.class,
EmbeddedWebApplicationContext.class })
// THESE excludes are not helping. !!!
public class MyIntegrationApplication {
public static void main(String[] args) throws InterruptedException {
System.exit(SpringApplication.exit(SpringApplication.run(
DelinquencyEngineApplication.class, args)));
}
}
由于我的classpath有Spring Web MVC jar(间接通过spring-boot-starter-integration依赖),尝试在main方法上面运行会导致这个execption: –
Exception in thread "main" 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)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
at com.hcentive.wfm.delinquency.DelinquencyEngineApplication.main(DelinquencyEngineApplication.java:27)
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)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:156)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130)
... 7 more
如何完全排除Web项目性质?在@SpringBootApplication上尝试了一些排除,但它没有帮助.
问题3
我应该如何处理优雅的关机?
当有人杀死Java应用程序时,我的应用程序不应该突然结束.
使用Spring Boot 1.2.3.
谢谢.
解决方法:
问题1
弹出启动应用程序将一直运行,直到您停止它.它是一个标准的Java应用程序.您可以使用java命令运行它
java -jar target/mymodule-0.0.1-SNAPSHOT.jar
主要问题是包装.看一下 :
问题2
new SpringApplicationBuilder(Application.class).web(false).run(args);
问题3
在控制台模式下,CTRL C将正常关闭.在守护进程模式下,Maven App汇编程序插件(嵌入JSW)将输出带有start / stop的shell脚本.
正如加里所建议的那样,请看Spring Integration Documentation about orderly shutdown
标签:java,spring-boot-2,spring-integration
来源: https://codeday.me/bug/20190623/1274466.html