In Spring Boot, annotations are used extensively. What is their main purpose?
Think about how Spring Boot reduces setup work.
Annotations in Spring Boot tell the framework what to do, like enabling web servers or database access, so developers don't write extra setup code.
Consider a Spring Boot app with a main class annotated with @SpringBootApplication. What does this annotation do?
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); } }
Think about what a typical Spring Boot app needs to start.
@SpringBootApplication is a shortcut annotation that combines @Configuration, @EnableAutoConfiguration, and @ComponentScan to set up the app automatically.
In Spring Boot, which annotation should you use on a class to automatically map HTTP requests to methods?
It combines controller behavior and response body handling.
@RestController marks a class as a web controller where every method returns data directly, enabling REST API endpoints.
Look at this Spring Boot main class. Why might the app fail to start?
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; public class App { public static void main(String[] args) { SpringApplication.run(App.class, args); } }
Check if the class is marked as a Spring Boot application.
Without @SpringBootApplication, Spring Boot does not know to auto-configure and scan components, so the app won't start correctly.
Which statement best describes how annotations influence the lifecycle of a Spring Boot application?
Think about what happens when the app starts and how Spring Boot knows what to do.
Annotations tell Spring Boot what beans to create and how to configure them automatically during startup, shaping the app lifecycle.