Unveiling SpringBoot’s Hidden Mechanics: From HelloWorld to Custom ClassLoaders

This article dives deep into SpringBoot’s inner workings, tracing a simple HelloWorld application from its main method through the startup call stack, FatJar packaging, custom ClassLoader behavior, and automatic controller registration via annotations, revealing why the framework feels both lightweight and monstrously complex.

Java Backend Technology
Java Backend Technology
Java Backend Technology
Unveiling SpringBoot’s Hidden Mechanics: From HelloWorld to Custom ClassLoaders

Hello World

SpringBoot can run a minimal HelloWorld application consisting of HelloController.java and Application.java. Executing Application.java starts an embedded Tomcat server that serves a simple REST endpoint.

SpringBoot Call Stack

The startup process can be followed through the call stack: SpringApplication.run() triggers component scanning, registers @RestController beans, and launches Tomcat. The author notes the stack depth, with most frames belonging to Tomcat and only a few to SpringBoot itself.

Exploring the FatJar ClassLoader

SpringBoot packages applications as a FatJar, placing all dependency JARs under BOOT-INF/lib and application classes under BOOT-INF/classes. Unlike the Maven Shade plugin, the FatJar keeps each JAR intact, making the internal structure clear. At runtime a custom JarLauncher replaces the Main-Class with its own launcher and adds a Start-Class parameter that points to the real business main method.

The custom ClassLoader first delegates to the JVM’s ExtensionClassLoader. If a class is not found, it searches the nested JARs in BOOT-INF/lib, caching package‑to‑JAR mappings to avoid repeated scans. The URL format for an embedded class looks like

jar:file:/.../application.jar!/BOOT-INF/lib/snakeyaml-1.19.jar!/org/yaml/snakeyaml/Yaml.class

.

HelloController Automatic Registration

Although HelloController is never referenced directly in Application.main, it is discovered by the @ComponentScan triggered by @SpringBootApplication. The @RestController annotation inherits from @Controller, which SpringBoot registers as a servlet handler in Tomcat, enabling the endpoint without explicit code.

Annotation Propagation

The chain starts with @SpringBootApplication, which includes @ComponentScan. This scans the current package for classes annotated with Spring stereotypes. When it encounters HelloController, the @RestController annotation causes the class to be turned into a URL handler and added to the servlet context.

Overall, the author expresses frustration with SpringBoot’s complexity and hidden mechanisms, yet acknowledges its ubiquity in modern Java development.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaclassloaderannotationsSpringBootFatJar
Java Backend Technology
Written by

Java Backend Technology

Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.