๐ด The Error You're Seeing
Confirm this matches your console output. If it does, you're in the right place.
2026-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)
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 packageResolve 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:treeFix @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
Standard component scanning.
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.