Spring Boot vs Plain Java: Choosing the Right Backend Stack
You need to build a backend service in Java. Should you reach for Spring Boot, or keep it simple with plain Java and the built-in HTTP server? This choice affects startup time, memory footprint, dependency management, and how quickly you can ship. This article breaks down the trade-offs so you can pick the right tool for your project.
What “Plain Java” Means for a Backend
Plain Java here means using the JDK's built-in com.sun.net.httpserver.HttpServer or a lightweight library like Javalin or Spark, without a full framework. You write your own routing, JSON parsing (e.g., with Jackson), and dependency wiring. The result is a minimal, fast-starting application with few dependencies.
What Spring Boot Brings to the Table
Spring Boot is an opinionated framework that bundles Spring MVC, embedded Tomcat, auto-configuration, and a vast ecosystem (Spring Data, Spring Security, Spring Cloud). It handles routing, dependency injection, configuration, and production-ready features like health checks and metrics out of the box.
Key Differences at a Glance
| Aspect | Spring Boot | Plain Java |
|---|---|---|
| Startup time | 1–5 seconds (typical) | Under 100 ms |
| Memory footprint | 200–500 MB | 20–50 MB |
| Learning curve | Steep (many concepts) | Gentle (just Java) |
| Built-in features | Extensive | Minimal |
| Dependency management | Starters simplify | Manual |
| Best for | Complex, enterprise apps | Microservices, CLIs, prototypes |
When to Choose Spring Boot
Spring Boot shines when your application needs:
- Rapid development with auto-configuration and starters.
- Integration with databases (JPA), security (OAuth2), and messaging (Kafka).
- Production readiness via Actuator endpoints for health, metrics, and tracing.
- Large team collaboration with consistent conventions.
If you're building a typical CRUD API with authentication, Spring Boot will save you weeks of boilerplate.
When to Choose Plain Java
Plain Java is a better fit when:
- Startup time and memory are critical (e.g., serverless, edge, or CLI tools).
- You want full control over every dependency and configuration.
- The service is small and focused, like a webhook receiver or a simple proxy.
- You're learning backend fundamentals and don't want framework magic.
Code Comparison: A Simple JSON API
Let's see how each approach handles a basic GET /hello endpoint that returns JSON.
Spring Boot
@RestController
public class HelloController {
@GetMapping("/hello")
public Map<String, String> hello() {
return Map.of("message", "Hello, World!");
}
}
With Spring Boot, you just annotate and run. The framework handles serialization, routing, and server setup.
Plain Java (com.sun.net.httpserver)
public class HelloServer {
public static void main(String[] args) throws IOException {
HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);
server.createContext("/hello", exchange -> {
String response = "{\"message\":\"Hello, World!\"}";
exchange.getResponseHeaders().set("Content-Type", "application/json");
exchange.sendResponseHeaders(200, response.length());
try (OutputStream os = exchange.getResponseBody()) {
os.write(response.getBytes());
}
});
server.start();
}
}
Plain Java requires manual JSON string construction and response handling. For more complex APIs, you'd add a JSON library and a router.
Performance and Resource Usage
Spring Boot's embedded server and auto-configuration add overhead. A minimal Spring Boot app typically uses 200–500 MB of heap and starts in 1–5 seconds. Plain Java with the built-in HTTP server can start in under 100 ms and use as little as 20–50 MB. If you're deploying many instances or using a serverless platform, this difference matters.
Ecosystem and Tooling
Spring Boot offers a rich ecosystem: Spring Data for databases, Spring Security for auth, Spring Cloud for microservices. It also integrates with build tools (Maven/Gradle) and IDEs seamlessly. Plain Java leaves you to assemble your own stack, which can be liberating but time-consuming.
Decision Guide: Which Should You Pick?
- Assess project complexity. If you need multiple integrations (DB, auth, messaging), Spring Boot wins.
- Consider deployment environment. For serverless or edge, plain Java's low overhead is advantageous.
- Evaluate team experience. Teams familiar with Spring will be more productive with it.
- Prototype both. Build a small endpoint in each to feel the difference.
FAQ
Can I use Spring Boot for a simple microservice?
Yes, but be aware of the resource overhead. If the service is truly minimal and you need fast startup, plain Java might be more efficient. Spring Boot is still a valid choice if you value its ecosystem and don't mind the footprint.
Is plain Java fast enough for production?
Absolutely. Java's built-in HTTP server is production-ready for many use cases, especially when paired with a reverse proxy like Nginx. However, you'll need to implement features like routing, JSON handling, and security yourself.
How do I migrate from plain Java to Spring Boot?
Start by identifying your core components: HTTP handlers, JSON serialization, and configuration. Spring Boot's starters can replace much of your manual code. Migrate incrementally, perhaps by wrapping your existing logic in Spring controllers.
Final Thoughts
There's no one-size-fits-all answer. Spring Boot accelerates development for complex applications, while plain Java gives you control and efficiency for simpler, performance-sensitive services. Evaluate your project's needs, team skills, and deployment targets to make the right call.
When you're ready to analyze your backend logs, try our Nginx Log Analyzer to gain insights into traffic and errors.