Skip to content
the poor coder

Can you disable the default web server in the Spring Boot application?

Poor Man
Published
Reading time
1 min read
On this page

Disabling the Default Web Server in a Spring Boot Application#

If you want to disable the default web server in a Spring Boot application, there are multiple ways to do it. However, before going into that, let's first understand what is meant by the default web server in a Spring Boot application.

Understanding the Default Web Server#

When you create a Spring Boot application, it comes with an embedded web server, which is used to serve your web content. The default web server that is included in a Spring Boot application is Apache Tomcat.

This embedded web server is included to make it easier for developers to get started with creating web applications. However, in some cases, you may want to disable the default web server and use a different web server instead. For example, you may want to use Nginx or Apache HTTP Server.

Disabling the Default Web Server#

There are multiple ways to disable the default web server in a Spring Boot application:

  • Using command-line arguments: You can disable the embedded web server by using the --server.port=-1 command-line argument when running your application. This will prevent the embedded web server from starting.
  • Using configuration properties: You can also disable the embedded web server by setting the spring.main.web-application-type=none configuration property in your application.properties (or application.yml) file. This will prevent the embedded web server from starting.
  • Using code: You can also disable the embedded web server by adding the @EnableAutoConfiguration(exclude = {EmbeddedServletContainerAutoConfiguration.class}) annotation to your main Spring Boot application class. This will exclude the embedded web server configuration from being loaded.

Conclusion#

Disabling the default web server in a Spring Boot application can be useful in some cases, such as when you want to use a different web server for your application. There are multiple ways to do it, including using command-line arguments, configuration properties, and code.

Text

@SpringBootApplication
@EnableAutoConfiguration(exclude = {EmbeddedServletContainerAutoConfiguration.class})
public class MySpringBootApp {

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

}

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC