Deploying Spring Boot Applications as WAR Files on External Tomcat

Configuring Maven for WAR Output

Modify the build configuration to change the artifact type. Set the packaging element to war within the POM.

<project>
    <groupId>com.example</groupId>
    <artifactId>enterprise-app</artifactId>
    <version>1.0.0</version>
    <packaging>war</packaging>
    <name>Enterprise Service</name>
</project>

Update the build section to define the final artifact name and ensure the Spring Boot plugin is present.

<build>
    <finalName>app-dist</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Excluding Embedded Container Dependencies

The embedded Tomcat starter must be marked as provided to prevent conflicts with the external container.

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <scope>provided</scope>
    </dependency>
</dependencies>

Implementing Servlet Initializer

Create a clas extending SpringBootServletInitializer to bootstrpa the application.

public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(EnterpriseApplication.class);
    }
}

Configuring Tomcat for Multiple Instances

Edit the conf/server.xml file to define separate services for each application.

<Server port="8005" shutdown="SHUTDOWN">
  <Service name="ServiceA">
    <Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000"/>
    <Engine name="Catalina" defaultHost="localhost">
      <Host name="localhost" appBase="dist/serviceA" unpackWARs="true" autoDeploy="true">
        <Context path="" docBase="enterprise-app.war" reloadable="true"/>
      </Host>
    </Engine>
  </Service>
  <Service name="ServiceB">
    <Connector port="8082" protocol="HTTP/1.1" connectionTimeout="20000"/>
    <Engine name="Catalina" defaultHost="localhost">
      <Host name="localhost" appBase="dist/serviceB" unpackWARs="true" autoDeploy="true">
        <Context path="" docBase="enterprise-app.war" reloadable="true"/>
      </Host>
    </Engine>
  </Service>
</Server>

Tags: Spring Boot Tomcat WAR deployment Maven java

Posted on Tue, 30 Jun 2026 17:57:41 +0000 by snk