Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Black Friday 2026 – NPI EA – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

1. Introduction

Spring Boot is a great framework for quickly creating new Java applications for a variety of use cases. One of the most popular uses is as a web server, using one of the many supported embedded servlet containers and template engines.

However, Spring Boot has a number of uses that do not require a web server: console applications, job scheduling, batch or stream processing, serverless applications, and more.

In this tutorial, we’ll look at several different ways to use Spring Boot without a web server.

2. Using Dependencies

The easiest way to prevent a Spring Boot application from starting an embedded web server is to not include the web server starter in our dependencies.

This means not including the spring-boot-starter-web dependency in either the Maven POM or Gradle build file. Instead, we would want to use the more basic spring-boot-starter dependency in its place.

Keep in mind it’s possible for Tomcat dependencies to be included in our application as transitive dependencies. In this case, we might need to exclude the Tomcat library from whichever dependency is including it.

3. Modifying the Spring Application

Another way to disable the embedded web server in Spring Boot is by using code. We can use either the SpringApplicationBuilder:

new SpringApplicationBuilder(MainApplication.class)
  .web(WebApplicationType.NONE)
  .run(args);

Or we can use the reference to the SpringApplication:

SpringApplication application = new SpringApplication(MainApplication.class);
application.setWebApplicationType(WebApplicationType.NONE);
application.run(args);

In either case, we have the benefit of keeping the servlet and container APIs available on the classpath. This means we can still use the web server libraries without starting the web server. This can be useful, for example, if we want to use them to write tests or use their APIs in our own code.

4. Using Application Properties

Using code to disable the web server is a static option — it will affect our application no matter where we deploy it. But what if we want to create the web server in specific circumstances?

In this case, we can use Spring application properties:

spring.main.web-application-type=none

Or using the equivalent YAML:

spring:
  main:
    web-application-type: none

The benefit of this approach is we can conditionally enable the web server. Using Spring profiles or conditionals, we can control the web server behavior in different deployments.

For example, we could have the web server running in development only to expose metrics or other Spring endpoints while keeping it disabled in production for security reasons.

Note that some earlier versions of Spring Boot used a boolean property named web-environment to enable and disable the web server. With the adoption of both traditional and reactive containers in Spring Boot, the property has been renamed and now uses an enum.

5. Conclusion

There are many reasons for creating Spring Boot applications without a web server. In this tutorial, we’ve seen multiple ways to do this. Each has its own pros and cons, so we should pick the approach that best meets our needs.

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Black Friday 2026 – NPI EA – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW