Explore fundamental Spring Boot concepts, annotations, and configuration features essential for backend development with Java. Challenge your understanding of application setup, REST APIs, dependency injection, and more.
Which annotation is used to mark a class as the main entry point for a Spring Boot application?
Explanation: @SpringBootApplication is the primary annotation that marks a configuration class as the main entry point in Spring Boot. @SpringBootMain does not exist. @Configuration enables Java-based configuration but does not designate the entry point. @EnableAutoConfiguration only enables auto-configuration but is usually included within @SpringBootApplication.
What does the @Autowired annotation do in a Spring component?
Explanation: @Autowired allows Spring to resolve and inject dependencies automatically. Automatic logging is handled by other configurations. Setting up REST endpoints uses different annotations, and scheduling tasks uses @Scheduled.
What is the default embedded server used by Spring Boot for running web applications?
Explanation: Tomcat is the default embedded servlet container in Spring Boot. Jetty and Undertow are supported alternatives but not defaults. Netty is used for non-servlet use cases and is not the default server.
Which file is commonly used to configure properties for a Spring Boot application?
Explanation: application.properties is the conventional file for configuration in Spring Boot, with application.yml also supported. config.xml and settings.json are used in other frameworks, while server.ini is unrelated to Spring Boot.
Which annotation is used in Spring Boot to create RESTful endpoints in a Java class?
Explanation: @RestController defines a class as a RESTful web service controller. @RequestMapping is used for mapping URLs but does not create REST controllers by itself. @Component is a general-purpose annotation and @Resource is used for dependency injection, not REST endpoints.
How do you map a method to handle HTTP GET requests in a Spring Boot application?
Explanation: @GetMapping maps HTTP GET requests to specific handler methods. @PostMapping is for POST requests. @RequestBody and @PathVariable are used as method parameters for request data but do not map HTTP methods themselves.
What is the main purpose of Spring Boot Actuator in an application?
Explanation: Spring Boot Actuator exposes endpoints to monitor, manage, and gain insights into a running application. Data validation, HTML rendering, and documentation are handled by other features or libraries.
Which annotation is used to handle exceptions globally across Spring Boot controllers?
Explanation: @ControllerAdvice is the correct way to apply global handling of exceptions across controllers. @ExceptionHandler is used for handling exceptions locally within a controller, and the other options are incorrect or non-existent in this context.
In Spring Boot JPA, which annotation marks a class as a persistent entity?
Explanation: @Entity is used to specify that a class is a JPA entity. @Table customizes table mapping, @Repository marks a data access layer, and @Data is a utility annotation from another library.
What does the @Service annotation indicate when placed on a Java class in Spring Boot?
Explanation: @Service is used for classes encapsulating business logic and marks them as service components managed by Spring. REST controllers use @RestController, repositories use @Repository, and entities use @Entity.