Performance: Why annotations drive Spring Boot
Annotations in Spring Boot affect application startup time and runtime configuration processing, impacting initial load speed and responsiveness.
@SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
@ComponentScan(basePackages = {"com.example"})
@Configuration
public class AppConfig {
@Bean
public Service service() {
return new ServiceImpl();
}
}| Pattern | Classpath Scanning | Reflection Calls | Startup Delay | Verdict |
|---|---|---|---|---|
| Broad @ComponentScan | High (many packages) | High (many classes) | High (hundreds ms) | [X] Bad |
| @SpringBootApplication with defaults | Low (default package) | Moderate (only needed classes) | Low (tens ms) | [OK] Good |
@RestController
public class HelloController {
@GetMapping("/hello")
public String sayHello() {
return "Hello, Spring!";
}
}/hello in a browser?@RestController
public class MyController {
@GetMapping("/data")
public String getData() {
return null;
}
}/data?com.example.app. Which annotation combination should you use on your main application class to achieve this?Pass the test and this pattern moves unknown