Learn. Practice. Feel prepared.
Spring Boot Objective Questions and Answers - Set 2
Test your Spring Boot skills with carefully curated MCQs designed for real-world development and interview preparation. Focused on configuration, REST APIs, data access, security, and production-ready applications. This is part 2 of the series.
Practice Spring Boot MCQs with Detailed Explanations
Answer at least 12 questions to submit and verify answers.
16 Which annotation is used to mark a class as a JPA entity? Easy
Correct answer:
@Entity
@Entity marks a class as a JPA-managed entity.
17 What is Spring Boot Actuator mainly used for? Medium
Correct answer:
Monitoring and management
Actuator provides production-ready endpoints for monitoring and managing applications.
18 Which profile is activated by default? Easy
Correct answer:
default
If no profile is specified, the default profile is used.
19 What is the use of @Primary annotation? Medium
Correct answer:
Specifies default bean for autowiring
@Primary indicates which bean should be preferred during autowiring.
20 Which cache abstraction is supported by Spring Boot? Medium
Correct answer:
Multiple cache providers
Spring Boot supports multiple cache providers through a unified abstraction.
21 What does @Transactional ensure? Medium
Correct answer:
Atomic database operations
@Transactional ensures operations execute within a database transaction.
22 Which annotation maps HTTP GET requests? Easy
Correct answer:
@GetMapping
@GetMapping is a shortcut for GET-specific request mapping.
23 Which layer should contain business logic in a typical Spring Boot application? Medium
Correct answer:
Service
The service layer encapsulates business logic and transactional boundaries.
24 What is the default JSON library used by Spring Boot? Medium
Correct answer:
Jackson
Jackson is the default JSON serialization/deserialization library.
25 Which annotation is used for asynchronous method execution? Medium
Correct answer:
@Async
@Async allows methods to execute asynchronously in a separate thread.
26 Which testing annotation loads only the web layer? Hard
Correct answer:
@WebMvcTest
@WebMvcTest focuses on testing controllers without loading full context.
27 What is the purpose of CommandLineRunner? Medium
Correct answer:
Execute code after application startup
CommandLineRunner runs specific code once the application context is loaded.
28 Which dependency enables JPA support? Easy
Correct answer:
spring-boot-starter-data-jpa
spring-boot-starter-data-jpa provides JPA and Hibernate support.
29 What is the default fetch type for @ManyToOne? Hard
Correct answer:
EAGER
@ManyToOne relationships are fetched eagerly by default.
30 Which annotation marks a method as read-only transaction? Hard
Correct answer:
@Transactional(readOnly = true)
readOnly=true hints the persistence provider for optimization.