Deploying Spring Boot applications as old-fashioned WAR files

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

Leider ist der Eintrag nur auf English verfügbar.

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

Your post must include a link to this post.

How does this work?
Write a response on your own website and include a link to this post. Then submit your response’s URL here. Your response may appear here after moderation. To update or remove it, edit or delete your original post and submit the same URL again. Learn more about Webmentions.