Reputation: 7765
I am trying to build a standalone Spring Integration application that has an inbound RabbitMQ based gate way. As the application needs not to handle HTTP requests, I want to make it a runnable Java project (that can be simple run using java -jar). I borrowed this idea after going through a 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.
PROBLEM 1
How should I start my Spring Boot application ? The Spring Boot Java application must run endlessly until interuppted.
PROBLEM 2
Exclude web project nature. Currently I trying my luck using :-
@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)));
}
}
As my classpath has Spring Web MVC jar (indirectly through spring-boot-starter-integration dependency ), trying to run above main method results in this 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
How can I completely exclude web project nature ? Tried some excludes on @SpringBootApplication but it didn't help.
PROBLEM 3
How should I handle graceful shutdown ? My application should not end abruptly when someone kills the Java application.
Spring Boot 1.2.3 is used.
Thanks.
Upvotes: 4
Views: 1400
Reputation: 4106
PROBLEM 1
A spring boot application will run until you stop it. It is a standard java application. You can run it using the java
command
java -jar target/mymodule-0.0.1-SNAPSHOT.jar
The main issue will be the packaging. Have a look at :
PROBLEM 2
To exclude the web nature you should use the SpringApplicationBuilder
builder
new SpringApplicationBuilder(Application.class).web(false).run(args);
PROBLEM 3
In console mode CTRL+C
will shutdown gracefully. In daemon mode, the Maven App assembler plugin (which embed JSW) will output a shell script with start/stop.
As suggested by Gary, see too Spring Integration Documentation about orderly shutdown
Upvotes: 4