• Register

Share:- Whatsapp Facebook Facebook

------------------------------------- Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.


0 votes
How do you Create a deployable war file in spring boot?
in Spring Boot by

1 Answer

0 votes

To Create a deployable war file in spring boot follows the following steps:-

Step1 :- Extend SpringBootServletInitializer:- The deployable war file is to provide a SpringBoot ServletInitializer subclass and override its configure method. This makes use of Spring Framework’s Servlet 3.0 support and allows you to configure your application when it’s launched by the servlet container.

package developerhelpway.com.spring.configuration;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@ComponentScan(basePackages = "developerhelpway.com")
@Import({ SpringConfiguration.class })
public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);

    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);


Step2:- In pom.xml file change packing to war:-


Step3:- Adding servlet container dependency in pom.xml file. The embedded servlet container doesn’t interfere with the servlet container to which the war file will be deployed. To do so, you need to mark the embedded servlet container dependency as provided. spring boot without embedded tomcat creates deployable war.


Step4:- Run maven with following command

mvn clean package

by (4.4k points)