Understanding Spring Boot's Startup Mechanism: Hello World, Call Stacks, FatJar, and Annotation‑Based Controller Registration
This article dissects how a simple Spring Boot Hello World application launches, walks through the runtime call stacks, explains the FatJar packaging and custom ClassLoader, and reveals how @RestController classes are automatically registered with the embedded Tomcat server.
Spring Boot may appear lightweight, but its startup process involves a complex chain of components. The author begins by showing a minimal Hello World project consisting of HelloController.java and Application.java, which together start an embedded RESTful web server.
Even though Application 's main method never directly references HelloController, Spring Boot discovers the controller through package scanning triggered by the @SpringBootApplication annotation, which includes @ComponentScan. Detected classes annotated with @RestController are automatically registered as URL handlers in the embedded Tomcat servlet container.
The article then presents the call stack of SpringApplication.run() and a typical HTTP request, illustrating that most of the deep stack frames belong to Tomcat, while Spring Boot contributes only a few layers.
Spring Boot packages the application as a FatJar, placing all dependency JARs under BOOT-INF/lib and the project's own classes under BOOT-INF/classes. Unlike the Maven Shade plugin, FatJar keeps each dependency JAR intact, making the final archive easier to inspect.
At runtime, a custom JarLauncher replaces the standard Main‑Class in the manifest, launches a special ClassLoader, and starts a new thread to load the real Start‑Class. This ClassLoader first checks the ExtensionClassLoader, then searches the cached package‑to‑JAR mappings, falling back to a linear scan of the nested JARs when necessary.
The custom ClassLoader also resolves URLs of the form
jar:file:/path/app.jar!/BOOT-INF/lib/xyz.jar!/org/example/Cls.class, enabling the JVM to load classes from inside the embedded JARs.
Finally, the author critiques the heavy reliance on annotations in Spring Boot, noting that while they simplify configuration, they also increase cognitive load and can make the source code harder to follow.
In conclusion, despite the author's frustration with Spring Boot's complexity and startup latency, the framework remains dominant in the Java ecosystem, and understanding its inner workings is essential for any backend developer.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Captain
Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
