This article shows how to create a deployable .war file using Spring Boot. When it comes to deployment, Spring Boot is very flexible, it allows you to build executable jar with embedded web container as well as war file that can be deployed in various application servers.
2. Create a deployable war file
The first step to take in order to make deployable war file is to create SpringBootServletInitializer subclass and override its configure method. This subclass should be annotated with @SpringBootApplication just like in jar file approach.
The next thing we should do is to make some changes in pom.xml or build.gradle file. Packaging should be set to war:
for pom.xml:
for build.gradle:
We also need to mark the embedded servlet container dependency as provided, to make sure that embedded servlet container will not be conflicted with servlet container on the server to which the war file will be deployed.
for pom.xml:
for build.gradle:
The fully formed pom.xml file prepared for creating war file, with minimum configuration, should have the following structure:
3. Conclusion
This article showcased how to build Spring Boot deployable war file instead of executable jar file. The tutorial should be useful for everyone who doesn't want to start their Spring Boot application with an embedded server but instead deploys war file on the different server.
Simple Maven application that creates war file with Spring is available on our GitHub repository with instructions how to run the app using docker.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}