Building and Deploying an SSM Backend Application with Maven and Tomcat

This article walks through creating a Java web backend using the SSM stack (Spring, Spring MVC, MyBatis) with Maven, packaging it as a WAR, and deploying it to Tomcat. Common configuration pitfalls are highlighted along the way.

1. Create a WAR‑based Maven project

Using your IDE, choose File → New → Maven Project → Create a simple project. Fill in the Group Id and Artifact Id, and set Packaging to war. Alternatively, generate the project from the command line:

mvn archetype:generate -DgroupId=com.example -DartifactId=ssm-backend -DarchetypeArtifactId=maven-archetype-webapp -Dversion=1.0-SNAPSHOT

2. Align the JDK version

Ensure that the JDK used to compile the project does not exceed the version installed on the target Tomcat server. If a higher‑version compiler is used, the deployed application will fail with an error such as unsupported major.minor version 52.0. Set the source and target language level in pom.xml via the Maven compiler plugin, for example:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.10.1</version>
  <configuration>
    <source>1.8</source>
    <target>1.8</target>
  </configuration>
</plugin>

3. Configure pom.xml

Add the required SSM dependencies – Spring Context, Spring Web MVC, MyBatis, a database connector, connection pooling, etc. A minimal dependency set would include:

<dependencies>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>5.3.26</version>
  </dependency>
  <dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-spring</artifactId>
    <version>2.1.0</version>
  </dependency>
  <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.33</version>
  </dependency>
  <!-- additional dependencies -->
</dependencies>

Also include the WAR plugin to control the packaging process:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-war-plugin</artifactId>
      <version>3.3.2</version>
      <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
      </configuration>
    </plugin>
  </plugins>
</build>

4. Configure web.xml with a /* mapping

The DispatcherServlet must be mapped to /* rather than /. Using / will prevent the Tomcat web application from starting and produce the message FAIL - Application at context path /YourApp could not be started.

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                             http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
  <display-name>SSM Application</display-name>
  
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring-*.xml</param-value>
  </context-param>
  
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  
  <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:springmvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  
  <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>

5. Create the Spring and MyBatis configuration files

Typical names are springmvc.xml, spring-mybatis.xml, spring-service.xml, and mybatis-config.xml. Place them under src/main/resources. Configure component scanning, view resolvers, DataSource, SqlSessionFactory, transaction management, and mapper scanning according to a standard SSM setup.

6. Add a sample controller

In the controller package, create a class to verify the setup:

package com.example.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class GreetingEndpoint {

    @ResponseBody
    @RequestMapping("/hello")
    public String sayHello() {
        return "Hello, World!";
    }
}

7. Clean the build

Right‑click the project (or use Maven CLI) and run mvn clean to remove stale artifacts.

8. Package the WAR

Execute mvn install. The compiled WAR file will be generated inside the target directory with the name <artifactId>.war.

9. Install the runtime environment

Install a JDK (matching the compiler version) and a Tomcat server (≥ 8.5). Start Tomcat and verify it runs on the default port 8080.

10. Deploy the WAR

Option A – direct copy: Drop the WAR file into the webapps directory of the Tomcat installation. Tomcat will automatically extract and deploy it under a context path matching the file name (minus the .war extension).

Option B – HTML manager GUI: First, enable the manager application by editing conf/tomcat-users.xml:

<tomcat-users>
  <role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <user username="admin" password="adminPass" roles="manager-gui,manager-script"/>
</tomcat-users>

Restart Tomcat, navigate to http://localhost:8080/manager/html, log in, and upload the WAR file through the **WAR file to deploy** section.

11. Verify the deployment

Access the deployed endpoint using the context path. If the artifact is named ssm-backend, the greeting endpoint becomes:

http://192.168.100.91:8080/ssm-backend/hello

You should see "Hello, World!" in the browser.

Tags: SSM Spring SpringMVC MyBatis Maven

Posted on Sun, 31 May 2026 15:59:27 +0000 by burn1337