Convert existing Spring MVC application to Spring Boot
Apr 25, 2015
2 minute read
Convert an existing Spring MVC application to Spring Boot
Until now I runned my web applications which I made with Spring MVC on a servlet container like Apache Tomcat.
Sometimes, if you like to start the application on a new machine it’s hard to get them running. You have to download Tomcat, deploy the app, and so on… It would be nice to start them like normal Java applications. For this reason I like to run my sample application with Spring Boot. Spring Boot will use an embedded tomcat to start the app.
Here wo go…
My sample project is build with maven.
First I have to add the “spring-boot-starter-web” dependency to my project:
For some reasons, in my case, spring was missing the aspectj-Library when starting
the application with spring boot. So I also added it:
Create executable application class
With the @SpringBootApplication Annotation you can tell spring boot, which class should be your executable application class.
To start the application you have to use the method SpringApplication.run().
Here you see my example:
The first parameter of the run()-Method takes the path to my spring-config-xml, I already had before, as a string.
Remove traditional “webapp” folder
In my Spring MVC application I had a “webapp” folder with the web.xml file, spring configuration files, and other properties-Files.
My new Spring boot app does not need the web.xml anymore, so I deleted it.
The other config-files I moved to the src/main/resources/META-INF directory:
Add maven plugin
To run my app with maven, I use the spring-boot-maven-plugin.
So I added it to my POM-File:
Run the application
Now I’m able to run my spring boot application with the following command: