4

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.

2
  • For Problem1 You can make your MyIntegrationApplication to implement CommandLineRunner interface .. Commented Apr 30, 2015 at 5:30
  • What should go inside the method of CommandLineRunner interface ? Commented Apr 30, 2015 at 5:59

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

8 Comments

PROBLEM 2 - Trying to run using the builder I am getting :- java.lang.IllegalAccessError: tried to access class org.springframework.context.annotation.MBeanExportConfiguration$SpecificPlatform from class org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration' Any idea what may be causing this ? Thanks
Seems related to this issue. Are you using at least the fix version or above?
@KumarSambhav with which spring core version? The one pull by spring boot?
it should depend on an old Spring version and Maven should have resolved to this version
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.