Deploying Spring Boot applications as old-fashioned WAR files

Home » Blog » Software » Enterprise Software » Deploying Spring Boot applications as old-fashioned WAR files

Spring Boot is an opinionated convention-over-configuration framework for creating stand-alone Spring-based Java applications.

Its objective is to provide you with a preselected best practice choice of libraries (both from the Spring platform and by third parties) for a given task, e.g.

  • building a web application that connects to a database and provides REST resources
  • creating a scheduled batch task that exports and aggregates data from various data sources
  • providing an API that connects to SOAP Web Services

It both helps you with getting started quickly and allows you to go about application development in a pattern-like manner that makes application behaviour more predictable and easier to understand.

In keeping with that stand-alone, cookie cutter approach the usual way Spring Boot applications are deployed is as a JAR file (including an embedded web container such as Tomcat if your application is a web app). This allows you to run your application right away without any configuration hassle. In addition to that, this self-contained approach is expedient to the microservices design pattern, which has made Spring Boot a prime choice for modern microservice architectures.

Sometimes however for instance due to existing infrastructure that can’t be changed quickly it might be necessary to deploy applications – web applications in particular – the old-fashioned way as WAR (Web application ARchive) files in existing servlet containers or application servers.

In order to do so you only have to make a few changes to your application configuration (as described in the Spring Boot documentation part on traditional deployment):

  • Provide a SpringBootServletInitializer and configure() method:
  • Change the packaging option in the application’s pom.xml to war:

  • Finally, tell Maven to not use the provided embedded Tomcat servlet container in production in order to not interfere with the existing servlet container you deploy the WAR file to:

If you’d like to know more about Spring Boot application deployment in general and converting Spring Boot applications from JAR to WAR deployments in particular please have a look at these posts on the Spring website:

About the author: Bjoern
Independent IT consultant, entrepreneur

Leave a Comment

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)