@SpringBootApplication annotation is a shortcut for combining multiple annotations. Which three annotations does it combine?The @SpringBootApplication annotation is a convenience annotation that combines @Configuration, @EnableAutoConfiguration, and @ComponentScan. This means it sets up configuration, enables Spring Boot's auto-configuration feature, and scans for components in the package.
@SpringBootApplication on the main class in package com.example.app, which packages will Spring scan for components by default?By default, @ComponentScan scans the package of the class it is declared on and all subpackages. Since @SpringBootApplication includes @ComponentScan, it scans com.example.app and all its subpackages.
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class MyApp { public static void main(String[] args) { SpringApplication.run(MyApp.class, args); } }
The method call SpringApplication.run(MyApp.class args); is missing a comma between the two arguments. It should be SpringApplication.run(MyApp.class, args);.
@SpringBootApplication starts?@SpringBootApplication enables auto-configuration, component scanning, and starts the embedded server (like Tomcat) automatically. This makes the application ready to run with minimal setup.
@SpringBootApplication on the main class. The app fails to start with a 'No qualifying bean' error for a service. What is the most likely cause?If the service class is in a package not scanned by Spring Boot (outside the main class package and its subpackages), Spring will not detect it as a bean, causing a 'No qualifying bean' error.