Search code examples
spring-bootspring-integrationspring-web

Combined Spring Boot integration & web application won't start


I have created two Spring Boot applications. One uses Spring Integration to read stuff from several feeds and the other combines the retrieved data from the feeds on a simple web page.

Currently these two exist as separate apps but I want to combine the two in a single application. The integration "application" is nothing more than a integration.xml and the other one is a couple of RestControllers.

In my Application class the integration application has the following in the main method:

    ConfigurableApplicationContext ctx = new SpringApplication("/feed/integration.xml").run(args);
    System.out.println("Hit Enter to terminate");
    final int read = System.in.read();
    System.out.println("Closing! (" + read + ")");
    ctx.close();

The web application has

    SpringApplication.run(MyWebApplication.class, args);

I've tried to combine the two resulting in:

    try {
        ConfigurableApplicationContext ctx = new SpringApplication("/feed/integration.xml").run(TrailerListApplication.class, args);
        System.out.println("Hit Enter to terminate");
        System.in.read();
        ctx.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

but that only starts the web application. The feeds don't get initialized. How can I make sure both components start and keep running?


Solution

  • Add @ImportResource("classpath:/feed/integration.xml") to MyWebApplication and just use

    SpringApplication.run(MyWebApplication.class, args);