๐Ÿ”ด The Error You're Seeing

Confirm this matches your console output. If it does, you're in the right place.

ERROR LOG2026-03-01 18:40:05.200 ERROR 8842 --- [ main] o.s.boot.SpringApplication : Application run failed org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:/path/to/lib.jar!/com/example/MyClass.class]; nested exception is java.lang.IllegalArgumentException

โšก Quick Fix Works 80% of the time

Run mvn dependency:tree to find conflicting libraries, or clean your target folder.

mvn clean install mvn dependency:tree -Dverbose

๐Ÿง  Why this Happens

Tap to expand the deep technical explanation

Spring's component scanner traverses the classpath looking for @Component classes. If it encounters a corrupted .class file, a JAR compiled with an incompatible Java version, or a malformed XML config file, it cannot parse it and crashes during startup.

The HITEC City Parking Spot Analogy:

Imagine a librarian trying to catalog new books. One of the books is printed in a language they don't understand (incompatible bytecode) or has missing pages (corrupt file). The librarian stops cataloging and reports an error.

๐Ÿ” How to Reproduce Confirm this is your error

Add a library that duplicates a bean/class definition on the classpath (or leave a corrupted JAR in the build), then start the app. Spring throws BeanDefinitionStoreException: Failed to read candidate component class.

๐Ÿ› ๏ธ Solutions (3 Ways to Fix)

Solution 1โœ“ Most common cause

Clean build artifacts

๐Ÿ‘‰ Use this if the build was interrupted, leaving corrupt .class files.

Stale or partially compiled class files in the target folder can cause Spring's component scanner to crash when it tries to read them.

mvn clean package
Solution 2

Resolve dependency conflicts

๐Ÿ‘‰ Use this if you recently added a new library that brings old Spring versions.

Spring Boot 3 requires Jakarta. If an older library pulls in javax.servlet or old Spring 5 classes, the scanner fails to read them.

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- Check for conflicts --> mvn dependency:tree
Solution 3

Fix @ComponentScan paths

๐Ÿ‘‰ Use this if your component scan is trying to read JARs it shouldn't.

If your @ComponentScan(basePackages = "com") is too broad, it might try to scan a corrupt or incompatible library JAR. Narrow it to your specific package.

@SpringBootApplication @ComponentScan(basePackages = "com.devinhyderabad") // Be specific public class Application { ... }

๐Ÿ“‹ Version Notes

Spring Boot 2.x

Standard component scanning.

Spring Boot 3.x

Stricter scanning, fails faster on incompatible bytecode.

๐Ÿ›ก๏ธ How to Prevent This Next Time

Keep dependencies updated. Use mvn clean frequently. Avoid overly broad component scanning.

Course Search
Search across all chapters & stages
๐Ÿ“–

Search the course

Type any topic โ€” branching, stash, rebase, hooks โ€” and jump straight to that chapter.

merge branchesgit stashundo commitrebase