【问题标题】:Standalone Spring Boot Integration Java Project独立的 Spring Boot 集成 Java 项目
【发布时间】: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


【解决方案1】:

问题 1

Spring Boot 应用程序将一直运行,直到您停止它为止。它是一个标准的 java 应用程序。您可以使用java 命令运行它

java -jar target/mymodule-0.0.1-SNAPSHOT.jar

主要问题是包装。看看:

问题 2

要排除网络性质,您应该使用SpringApplicationBuilder 构建器

new SpringApplicationBuilder(Application.class).web(false).run(args);

问题 3

在控制台模式下CTRL+C 将正常关闭。在守护进程模式下,Maven App 汇编器插件(嵌入JSW)将输出一个带有启动/停止的shell 脚本。 正如 Gary 所建议的那样,请参阅 Spring Integration Documentation about orderly shutdown

【讨论】:

  • 问题 2 - 尝试使用我得到的构建器运行:- java.lang.IllegalAccessError: 试图访问类 org.springframework.context.annotation.MBeanExportConfiguration$SpecificPlatform 从类 org.springframework.boot .autoconfigure.jmx.JmxAutoConfiguration' 知道是什么原因造成的吗?谢谢
  • 似乎与this issue 相关。您至少使用的是修复版本或更高版本吗?
  • @KumarSambhav 使用哪个弹簧核心版本?弹簧靴的一拉?
  • 它应该依赖于旧的 Spring 版本并且 Maven 应该已经解析到这个版本
猜你喜欢
  • 2018-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-28
相关资源
最近更新 更多