Video in progress
What's inside @SpringBootApplication?
It's a combination of three annotations: @SpringBootConfiguration (i.e. @Configuration), @EnableAutoConfiguration and @ComponentScan.
📖 Answer
@SpringBootApplication
public class ShopApplication {
public static void main(String[] args) {
SpringApplication.run(ShopApplication.class, args);
}
}
One annotation does three jobs:
@SpringBootConfiguration— the class is a configuration source; you can write@Beanmethods in it.@EnableAutoConfiguration— turns on Boot's auto-configs based on the classpath.@ComponentScan— looks for@Component,@Serviceand the rest in this class's package and its subpackages.
Hence the practical rule: put the main class in the top-level package (uz.shop). If it sits in uz.shop.app while the services are in uz.shop.order, they won't be found and you'll get a "bean not found" error. This happens a lot in new projects.
If you don't need some auto-config: @SpringBootApplication(exclude = DataSourceAutoConfiguration.class).
Sign up to mark studied questions and save your progress.