Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Spring Integration Standalone Application with Spring Boot

DZone's Guide to

Spring Integration Standalone Application with Spring Boot

· Java Zone
Free Resource

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

I had earlier blogged about a way to write a standalone Spring Integration application. Spring Boot makes creating this standalone application much simpler.

The simple flow was to poll the USGS service providing information about the earthquake activity around the world and to log this information. The flow described using Spring Integration is the following:
<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>
Pre-boot, the way to write a main program to start this flow would have been along these lines:

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();
 }
}
With Spring-boot however the configuration is IMHO simpler:
mvn spring-boot:run
I had a very small hand in fixing this start-up script by contributing a change to the plugin to start-up the application without needing to manually run the compilation step first.

Even better, the spring-boot-maven-plugin provides tools to package the entire application into a executable jar which gets triggered during the package phase, along the lines of shade plugin:
mvn package
and the executable jar run this way:
java -jar target/si-standalone-sample-1.0-SNAPSHOT.jar

An updated project with this change is available at this github location - https://github.com/bijukunjummen/si-standalone-sample

The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!

Topics:

Published at DZone with permission of Biju Kunjummen, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}