Can you deploy a Spring Boot application as a traditional WAR file to an external server?

A Spring Boot application can be deployed as a traditional WAR file to an external servlet container like Apache Tomcat or JBoss, though this is less common than the default embedded-server, executable-JAR deployment model.

Key Points: • Change the Maven or Gradle packaging setting from jar to war. • Extend SpringBootServletInitializer in the main application class to bridge Spring Boot's startup with the servlet container's lifecycle. • Mark the embedded server dependency (like spring-boot-starter-tomcat) as provided so it doesn't conflict with the external container's own server. • Deploy the resulting WAR by dropping it into the server's deployment directory or using its management console. • This approach is typically chosen when an organization mandates a specific shared application server for operational or compliance reasons.

Example: A regulated enterprise environment that requires all applications to run under a centrally managed Tomcat cluster deploys its Spring Boot service as a WAR rather than using the default embedded-server JAR.

Code Example:

public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(Application.class);
    }
}

Interview Tip: A concise interview answer is:

"Yes, I'd switch packaging to WAR, extend SpringBootServletInitializer, and mark the embedded Tomcat dependency as provided so it doesn't clash with the external server. That lets me deploy to a traditional server like Tomcat or JBoss when the organization requires a shared, centrally managed application server."