39
votes

I have an existing spring 3.1.4 application that works fine and boots up ok on its own. I currently start the spring context manually in a main class of my own. This is NOT a spring-mvc app, it does not contain any servlets, web.xml nor does it generate a WAR. It just produces a JAR for an integration backend.

I would like "wrap" this legacy application and launch it with spring-boot. However I am having trouble figuring out how to do this as all the examples seem to assume creating a "new" application.

1) I have my existing applicationContext.xml file with my existing spring app bean declarations in it

2) What is the minimum set of new bean configs that I need to add to my existing Spring applicationContext.xml file in order to have spring-boot w/ tomcat launched and load all of my existing beans into the spring-boot wrapped context?

Can anyone point me in the right direction please?

1
If it isn't a web app then why use Spring Boot with Tomcat? Just don't use the web dependency and let spring boot create the context for you. Spring Boot doen't require to be a web based application. You can use it for command line apps as well.M. Deinum

1 Answers

44
votes

There is a chapter dedicated to Converting an existing application to Spring Boot in the Spring Boot reference guide.

Basically you need to add the Spring Boot dependencies and then implement the main entry point like this:

@SpringBootApplication
@ImportResource("classpath:applicationContext.xml")
public class MySpringBootApplication {
    public static void main(String[] args) {
        SpringApplication.run(MySpringBootApplication.class, args);
    }
}

However, this will also trigger Spring Boot's auto-configuration based upon (among other things) available classes and configured beans. You might want to disable certain auto-configurations. To exclude DataSource and Hibernate JPA auto-configuration, use:

@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class })