独立Spring Boot集成Java项目
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了独立Spring Boot集成Java项目,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3632字,纯文字阅读大概需要6分钟。
内容图文
我正在尝试构建一个独立的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
主要问题是包装.看一下 :
> Spring Boot Maven plugin
> Maven App assembler plugin
问题2
要排除Web性质,应使用SpringApplicationBuilder构建器
new SpringApplicationBuilder(Application.class).web(false).run(args);
问题3
在控制台模式下,CTRL C将正常关闭.在守护进程模式下,Maven App汇编程序插件(嵌入JSW)将输出带有start / stop的shell脚本.
正如加里所建议的那样,请看Spring Integration Documentation about orderly shutdown
内容总结
以上是互联网集市为您收集整理的独立Spring Boot集成Java项目全部内容,希望文章能够帮你解决独立Spring Boot集成Java项目所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。