Bird
0
0

Given this main class code snippet, what will happen when you run it?

medium📝 component behavior Q13 of 15
Spring Boot - Spring Annotations
Given this main class code snippet, what will happen when you run it?
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);
    }
}
AThe Spring Boot application starts with auto-configuration and component scanning.
BThe application throws a runtime error due to missing @ComponentScan.
CThe application starts but without any auto-configuration.
DThe code will not compile because @SpringBootApplication is missing parameters.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the use of @SpringBootApplication

    The annotation enables auto-configuration and component scanning by default.
  2. Step 2: Check the main method execution

    The SpringApplication.run() method starts the Spring Boot app with all default behaviors.
  3. Final Answer:

    The Spring Boot application starts with auto-configuration and component scanning. -> Option A
  4. Quick Check:

    @SpringBootApplication triggers auto-config and scanning [OK]
Quick Trick: Default behavior includes auto-config and scanning [OK]
Common Mistakes:
  • Assuming @ComponentScan is required separately
  • Thinking auto-configuration is off by default
  • Believing parameters are mandatory for @SpringBootApplication

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes