java 项目集成spring,独立Spring Boot集成Java项目

我正在尝试构建一个独立的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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值