Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrate existing spring app to spring-boot, manually configure spring-boot?

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?

like image 268
bitsofinfo Avatar asked Jul 14 '15 14:07

bitsofinfo


People also ask

Can we convert spring application to Spring Boot?

Migrate a Spring Data ApplicationIf we want to work with a different database type and configuration, such as a MySQL database, then we need the dependency as well as to define a configuration. Spring Boot will auto-configure Hibernate as the default JPA provider, as well as a transactionManager bean.


1 Answers

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 }) 
like image 103
hzpz Avatar answered Nov 07 '22 15:11

hzpz