Can we disable the default web server in a Spring Boot application?

Yes, Spring Boot allows us to disable the embedded web server and run the application as a non-web application. This is useful for applications that perform background processing, batch jobs, message consumption, scheduling tasks, or command-line operations where HTTP endpoints are not required.

Key Points: • Disabling the web server prevents Spring Boot from starting Tomcat, Jetty, or Undertow. • It reduces resource usage and startup time for non-web applications. • Commonly used for batch processing, schedulers, and message-driven applications. • Can be configured using application properties or programmatically. • The application still benefits from Spring's dependency injection and configuration management.

Why Disable the Web Server?

Not every Spring Boot application exposes REST APIs or web pages.

Examples:

• Batch processing jobs • Kafka consumers • RabbitMQ consumers • Data migration tools • Scheduled background services • Command-line applications

In these cases, starting an embedded web server is unnecessary.

How to Disable the Web Server?

Method 1: Using application.properties

application.properties

spring.main.web-application-type=none

This prevents Spring Boot from starting any embedded web server.

Method 2: Using application.yml

spring: main: web-application-type: none

This achieves the same result using YAML configuration.

Method 3: Programmatically

Code Example:

import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;

public class Application {

    public static void main(String[] args) {

        new SpringApplicationBuilder(Application.class)

.web(WebApplicationType.NONE)

                .run(args);
    }
}

This explicitly tells Spring Boot to run as a non-web application.

What Happens Internally?

Application Starts | Spring Context Created | Beans Initialized | No Embedded Server Started | Application Ready

The Spring container starts normally, but Tomcat, Jetty, or Undertow is not launched.

Example: Suppose a company develops a nightly data processing application.

Responsibilities:

• Read files from a directory • Process records • Store results in a database

No REST APIs are needed.

Configuration:

spring.main.web-application-type=none

Result:

• No web server starts. • Lower memory usage. • Faster startup.

Benefits

• Reduced memory consumption • Faster application startup • Better performance for background tasks • Simpler deployment for non-web workloads • Avoids unnecessary server initialization

Common Use Cases

• Batch jobs using Spring Batch • Kafka consumers • RabbitMQ listeners • Scheduled tasks • Data synchronization services • Command-line utilities

Default Behavior

By default:

spring-boot-starter-web

starts:

• Embedded Tomcat (default) • Jetty (if configured) • Undertow (if configured)

When:

spring.main.web-application-type=none

is set, Spring Boot skips the web server initialization process entirely.

Interview Tip: A concise interview answer is:

"Yes, we can disable the embedded web server in Spring Boot by setting spring.main.web-application-type=none in application.properties or application.yml. This converts the application into a non-web application, which is useful for batch processing, scheduled jobs, messaging applications, and other background services where HTTP endpoints are not required."