The full picture
- Placement rule:
com.acme.orders.OrdersApplicationscanscom.acme.orders.**— acom.acme.shared.PricingServiceis NOT found. Fix withscanBasePackagesor (better) restructure; implicit invisibility is the bug generator. - Test hook:
@SpringBootTestwalks up packages to find@SpringBootConfiguration— why tests magically locate your app class, and why two application classes in one module break test slices. - Exclusions:
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)for 'I have the jar but not the infra' cases (e.g., a library dragged in JPA). - Scanning cost & hygiene: each scanned class is ASM-read at startup; keep the tree tight, and use
@ComponentScan(excludeFilters=…)sparingly — if you're filtering a lot, your packages are wrong.
com.acme.orders
└── OrdersApplication.java // @SpringBootApplication — scan root
com.acme.common
└── AuditService.java // @Service … and silently NEVER registered
// NoSuchBeanDefinitionException at startup (if constructor-injected — fail fast!)
// Options:
@SpringBootApplication(scanBasePackages = {"com.acme.orders", "com.acme.common"})
// or: move OrdersApplication up to com.acme
// or (library-grade): ship com.acme.common with its own @AutoConfiguration