具有Spring Boot的Spring Integration Standalone应用程序

之前在博客中写过一种编写独立的Spring Integration应用程序的方法。
Spring Boot使创建此独立应用程序变得更加简单。

简单的流程是轮询USGS服务,以提供有关世界各地地震活动的信息并记录该信息。 使用Spring Integration描述的流程如下:

<int:inbound-channel-adapter channel="quakeinfotrigger.channel" expression="''">
  <int:poller fixed-delay="60000"></int:poller>
 </int:inbound-channel-adapter>

 <int:channel id="quakeinfo.channel">
  <int:queue capacity="10"/>
 </int:channel>

 <int:channel id="quakeinfotrigger.channel"></int:channel> 

 <int-http:outbound-gateway id="quakerHttpGateway"
     request-channel="quakeinfotrigger.channel"
     url="http://earthquake.usgs.gov/earthquakes/feed/geojson/all/hour"
     http-method="GET"
     expected-response-type="java.lang.String"
     charset="UTF-8"
     reply-timeout="5000"
     reply-channel="quakeinfo.channel">     
 </int-http:outbound-gateway>

 <int:logging-channel-adapter id="messageLogger" log-full-message="true" channel="quakeinfo.channel" level="ERROR">
  <int:poller fixed-delay="5000" ></int:poller>
 </int:logging-channel-adapter>

在预引导过程中,编写主程序以启动此流程的方式应遵循以下原则:

package standalone;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
 public static void main(String[] args) {
  ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:/httpgateway.xml");
  applicationContext.registerShutdownHook();
 }
}

但是,使用Spring-boot,恕我直言,配置更简单:

package standalone;

import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

@Configuration
@ImportResource("classpath:httpgateway.xml")
public class Main {

 public static void main(String[] args) {
  SpringApplication.run(Main.class, args);
 }
}

并通过此更改以及spring-boot-maven-plugin插件,可以通过以下方式启动应用程序:

mvn spring-boot:run

我有一个非常小在通过促进变化的插件来启动应用程序,而无需手动首先运行编译步骤解决这个启动脚本。

甚至更好的是,spring-boot-maven-plugin提供了将整个应用程序打包到可执行jar中的工具,该jar在打包阶段会被触发,如遮阳插件所示:

mvn package

可执行的jar运行如下:

java -jar target/si-standalone-sample-1.0-SNAPSHOT.jar
  • 可在此github位置获得具有此更改的更新项目– https://github.com/bijukunjummen/si-standalone-sample


翻译自: https://www.javacodegeeks.com/2014/02/spring-integration-standalone-application-with-spring-boot.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值