Spring Boot MCQ Questions and Answers | Set 3


Welcome to Set 3 of our 100 Spring Boot MCQ Questions and Answers series, where we continue to unravel the complexities of Spring Boot. Having built a solid foundation with the basics and intermediate topics covered in the first two sets, this third instalment elevates your learning journey into advanced Spring Boot features and annotations.

Complete Spring Boot MCQ Questions and Answers series:

Spring Boot MCQ Questions and Answers | Set 1

Spring Boot MCQ Questions and Answers | Set 2

Spring Boot MCQ Questions and Answers | Set 3

Spring Boot MCQ Questions and Answers | Set 4

Spring Boot MCQ Questions and Answers | Set 5

Spring Boot MCQ Questions and Answers | Set 6

Spring Boot MCQ Questions and Answers | Set 7

Spring Boot MCQ Questions and Answers | Set 8

Spring Boot MCQ Questions and Answers | Set 9

Spring Boot MCQ Questions and Answers | Set 10

21. What is the purpose of the @ConfigurationProperties annotation in Spring Boot?

a) To define controller methods
b) To bind external configuration properties to a Java object
c) To create HTML templates
d) To configure Spring Security

Answer:

b) To bind external configuration properties to a Java object

Explanation:

The @ConfigurationProperties annotation in Spring Boot is used to bind external configuration properties (typically from application.properties or application.yml) to a bean, allowing type-safe configuration.

22. Which dependency is used to include Spring Security in a Spring Boot project?

a) spring-boot-starter-security
b) spring-boot-starter-web
c) spring-boot-starter-data-jpa
d) spring-boot-starter-actuator

Answer:

a) spring-boot-starter-security

Explanation:

The spring-boot-starter-security starter includes dependencies required for using Spring Security in a Spring Boot application, providing authentication and authorization capabilities.

23. How does Spring Boot support database migrations?

a) Using the @Entity annotation
b) Through the Spring Data JPA
c) By integrating with tools like Flyway or Liquibase
d) By providing its own database migration tool

Answer:

c) By integrating with tools like Flyway or Liquibase

Explanation:

Spring Boot supports database migrations by integrating with migration tools like Flyway and Liquibase, facilitating version control for your database schema.

24. What is the default scope of a Spring bean in Spring Boot?

a) Prototype
b) Request
c) Singleton
d) Session

Answer:

c) Singleton

Explanation:

In Spring Boot, the default scope of a Spring bean is 'Singleton'. This means that only one instance of the bean is created and shared across the entire application.

25. What is the purpose of the @Service annotation in Spring Boot?

a) To define a REST controller
b) To mark a class as a service provider
c) To create scheduled tasks
d) To configure application properties

Answer:

b) To mark a class as a service provider

Explanation:

The @Service annotation in Spring Boot marks a class as a service provider, indicating that it holds business logic. This stereotype annotation also makes the class eligible for auto-detection and auto-configuration.

26. What is the role of the spring-boot-starter-actuator dependency?

a) To provide RESTful web service capabilities
b) To add support for WebSocket communication
c) To enable Spring Security features
d) To include production-ready features like health indicators and metrics

Answer:

d) To include production-ready features like health indicators and metrics

Explanation:

The spring-boot-starter-actuator starter adds actuator support, which includes production-ready features like health checks, metrics, and environment information useful for monitoring and managing the application.

27. How can you specify the profile-specific configuration in Spring Boot?

a) By creating separate XML files for each profile
b) By using annotations like @Profile
c) By naming property files with the profile name (e.g., application-dev.properties)
d) By defining environment variables

Answer:

c) By naming property files with the profile name (e.g., application-dev.properties)

Explanation:

Profile-specific configurations in Spring Boot can be managed by naming the properties files with the profile name, such as application-dev.properties for the 'dev' profile and application-prod.properties for the 'prod' profile.

28. In Spring Boot, what is the purpose of the @Scheduled annotation?

a) To define a scheduled task
b) To configure a REST endpoint
c) To mark a class as a JPA entity
d) To define a service class

Answer:

a) To define a scheduled task

Explanation:

The @Scheduled annotation in Spring Boot is used to define methods that should be executed at a fixed interval or cron expression, enabling the creation of scheduled tasks.

29. How does Spring Boot simplify database access?

a) By providing a built-in database
b) Through automatic configuration of DataSource and JdbcTemplate
c) By requiring manual configuration of database connections
d) By using XML configuration files

Answer:

b) Through automatic configuration of DataSource and JdbcTemplate

Explanation:

Spring Boot simplifies database access by automatically configuring DataSource and JdbcTemplate based on the database and driver dependencies in the classpath.

30. What is the role of the @RequestBody annotation in a Spring Boot controller?

a) To bind a method parameter to a web request body
b) To define a request parameter
c) To return a response body
d) To configure request headers

Answer:

a) To bind a method parameter to a web request body

Explanation:

The @RequestBody annotation in Spring Boot is used in controller methods to bind the HTTP request body to a method parameter. It is typically used with POST and PUT HTTP methods.

Complete Spring Boot MCQ Questions and Answers Series:

Spring Boot MCQ Questions and Answers | Set 1

Spring Boot MCQ Questions and Answers | Set 2

Spring Boot MCQ Questions and Answers | Set 3

Spring Boot MCQ Questions and Answers | Set 4

Spring Boot MCQ Questions and Answers | Set 5

Spring Boot MCQ Questions and Answers | Set 6

Spring Boot MCQ Questions and Answers | Set 7

Spring Boot MCQ Questions and Answers | Set 8

Spring Boot MCQ Questions and Answers | Set 9

Spring Boot MCQ Questions and Answers | Set 10


Comments