【发布时间】:2015-07-09 15:49:00
【问题描述】:
我正在尝试构建一个独立的 Spring Integration 应用程序,该应用程序具有基于入站 RabbitMQ 的网关方式。由于应用程序不需要处理 HTTP 请求,我想让它成为一个可运行的 Java 项目(可以使用 java -jar 简单运行)。我通过Spring Batch Guide example 后借用了这个想法:-
使应用程序可执行
虽然批处理可以嵌入到 Web 应用程序和 WAR 文件中, 下面演示的更简单的方法创建了一个独立的 应用。您将所有内容打包在一个可执行的 JAR 文件中, 由一个很好的旧 Java main() 方法驱动。
问题 1
我应该如何启动我的 Spring Boot 应用程序? Spring Boot Java 应用程序必须无休止地运行,直到被中断。
问题 2
排除网络项目性质。 目前我正在尝试我的运气:-
@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)));
}
}
由于我的类路径有 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
我怎样才能完全排除网络项目性质?在@SpringBootApplication 上尝试了一些排除,但没有帮助。
问题 3
我应该如何处理正常关机? 当有人杀死 Java 应用程序时,我的应用程序不应突然结束。
使用的是 Spring Boot 1.2.3。
谢谢。
【问题讨论】:
-
对于 Problem1 你可以让你的 MyIntegrationApplication 实现 CommandLineRunner 接口 ..
-
CommandLineRunner接口的方法里面应该放什么?
标签: java spring-boot spring-integration