[英]Standalone Spring Boot Integration Java Project
I am trying to build a standalone Spring Integration application that has an inbound RabbitMQ based gate way. 我正在尝试构建一个独立的Spring Integration应用程序,它具有基于入站RabbitMQ的门控方式。 As the application needs not to handle HTTP requests, I want to make it a runnable Java project (that can be simple run using java -jar).
由于应用程序不需要处理HTTP请求,我想让它成为一个可运行的Java项目(可以使用java -jar简单运行)。 I borrowed this idea after going through a Spring Batch Guide example :-
我在完成Spring Batch Guide示例后借用了这个想法: -
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.
虽然批处理可以嵌入到Web应用程序和WAR文件中,但下面演示的更简单的方法创建了一个独立的应用程序。 You package everything in a single, executable JAR file, driven by a good old Java main() method.
您将所有内容打包在一个可执行的JAR文件中,由一个好的旧Java main()方法驱动。
PROBLEM 1 问题1
How should I start my Spring Boot application ? 我该如何启动Spring Boot应用程序? The Spring Boot Java application must run endlessly until interuppted.
Spring Boot Java应用程序必须无休止地运行,直到被中断。
PROBLEM 2 问题2
Exclude web project nature. 排除Web项目性质。 Currently I trying my luck using :-
目前我正在尝试运气: -
@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)));
}
}
As my classpath has Spring Web MVC jar (indirectly through spring-boot-starter-integration dependency ), trying to run above main method results in this execption:- 由于我的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
How can I completely exclude web project nature ? 如何完全排除Web项目性质? Tried some excludes on @SpringBootApplication but it didn't help.
在@SpringBootApplication上尝试了一些排除,但它没有帮助。
PROBLEM 3 问题3
How should I handle graceful shutdown ? 我应该如何处理优雅的关机? My application should not end abruptly when someone kills the Java application.
当有人杀死Java应用程序时,我的应用程序不应该突然结束。
Spring Boot 1.2.3 is used. 使用Spring Boot 1.2.3。
Thanks. 谢谢。
PROBLEM 1 问题1
A spring boot application will run until you stop it. 弹出启动应用程序将一直运行,直到您停止它。 It is a standard java application.
它是一个标准的Java应用程序。 You can run it using the
java
command 您可以使用
java
命令运行它
java -jar target/mymodule-0.0.1-SNAPSHOT.jar
The main issue will be the packaging. 主要问题是包装。 Have a look at :
看一下 :
PROBLEM 2 问题2
To exclude the web nature you should use the SpringApplicationBuilder
builder 要排除Web性质,您应该使用
SpringApplicationBuilder
构建器
new SpringApplicationBuilder(Application.class).web(false).run(args);
PROBLEM 3 问题3
In console mode CTRL+C
will shutdown gracefully. 在控制台模式下,
CTRL+C
将正常关闭。 In daemon mode, the Maven App assembler plugin (which embed JSW ) will output a shell script with start/stop. 在守护进程模式下,Maven App汇编程序插件(嵌入JSW )将输出带有start / stop的shell脚本。 As suggested by Gary, see too Spring Integration Documentation about orderly shutdown
正如Gary所建议的那样,请参阅关于有序关闭的Spring Integration Documentation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.