Skip to main content

Posts

Showing posts with the label Java Production Ready

🧙 How Does Spring Boot Really Find Stuff?! (And How @SpringBootApplication + META-INF/spring.factories Do Their Secret Scan Magic)

  😵‍💫 When I started working in Spring Boot, I had a silly doubt… but it unlocked a serious concept . I knew that @SpringBootApplication does a lot — it’s the entry point of every Spring Boot app. So far, I only knew the basics: @SpringBootApplication = @Configuration + @EnableAutoConfiguration + @ComponentScan But one day I asked myself: 💭 “How does Spring Boot load classes from external libraries like spring-security , spring-web , or even a custom JAR I wrote and added in dependencies? I never wrote any @ComponentScan for them… so how are their beans magically appearing inside my Spring Context?” Yeah yeah… people say “Auto-configuration” or “Classpath scanning.” But how ? Let’s deep dive 🔍 🚪 Let’s First Talk About @ComponentScan By default, this only scans packages below the class where @SpringBootApplication is placed. So if your MainApp.java is in com.anand.app , it will scan: com.anand.app.* But will it scan classes inside: org.springframework.sec...