Spring Boot External Tomcat Configuration

In the example, we can run Spring Boot with Spring MVC project on External Tomcat in eclipse.


You can obtain more information about the Tomcat server from this website https://tomcat.apache.org/download-90.cgi.You can extract the folder from the downloaded zip folder. You can place this extracted folder in some location on your computer or laptop.

Open Eclipse and select your workspace. After that, you go to 

Window → Preferences


Select Server → Runtime Environment


Click On Add button


Select the Tomcat server and click on the Add button


Click on Apache


Select Tomcat Server Version

Click on the Next button


Browse the path of the Tomcat Server of the system

Click on the Finish button 

Then click on Apply and close.

After that, you configured Tomcat successfully. Now you can create the Spring Boot Project.

Development Process:
1. Keep eclipse IDE ready(STS integrated)
2. Create a Spring Boot Starter Project 
3. Create a view page
4. Create a Controller class
5. Define View Resolver Path in application.properties
6. Run the Project

1. Keep eclipse IDE ready(STS Integrated) 
Refer to this article How to Create Spring Project in IDE to create Spring Boot Project in Eclipse IDE.

2. Create a Spring Boot Starter Project 
Select packaging war and Add the following dependencies: 
     • Spring Web


ServletInitializer class:

package com.example;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer {

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

→ This class is automatically generated when we select packaging as the war of project creation.
→ A pontifical WebApplicationInitializer to run a SpringApplication from a traditional WAR deployment. It wraps Servlet, Filter and ServletContextInitializer beans from the application context to the server.
→ This class is needed when we are building a war file and deploying it on the external server. If you can prefer to run an embedded web server then you won’t need this at all.
SpringBootApplication class:

package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class SpringBootWithSpringMvcApplication {

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

Maven Dependency

 <?xml version="1.0" encoding="UTF-8"?>
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
		<relativePath/> <!-- lookup parent from repository -->
	<description>Demo project for Spring Boot</description>




3. Create a view page
home. jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html>
<meta charset="ISO-8859-1">
<b> You have Successfully  Developed Spring Boot App on External Tomcat Server</b>

→ Create under the WEB-INF/view folder.
4. Create a Controller class

package com.example.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

public class HomeController {
	public String msg() {
                    //return a view page name

5. Define View Resolver Path in the application.properties file


6. Run the Project
Right-click on this project then click Run as Run on Server. Then you will show a window popup and select the localhost. After that select tomcat and click on the Next button. Thus select the project which you want to run on this server. Finally, our project will be running and automatically switch to the browser and show our home page as a response output.


This example is explained How to add the Tomcat Server in eclipse’s workspace and run our Spring Boot Project on an external Tomcat Server.

Leave a Comment