How to create a WAR file in Spring Boot
1. Extending Main Class
First, we need to extend our main class to SpringBootServletInitializer. This tells Spring that your main class will be the entry point to initialize your project in the server.
2. Overriding configure method
Next, we overload the configure method of SpringBootServletInitializer. We tell Spring to build the sources from our Main class. Your final Main class should look like this:
3. Configure Packaging to WAR
Finally, we tell Maven to package the project into WAR. In your pom.xml, change the attribute value for packaging from jar to war
<packaging>war</packaging>
Then try to build your project using
mvn package
You can now package your application with a jar or war file. Just change the packaging to either jar or war. And also you can still run your main method in your IDE to develop the application.