Spring Boot MCQ Questions and Answers | Set 7

Welcome to Set 7 of our 100+ Spring Boot MCQ Questions and Answers series. This Set 7 continues from MCQs 61-70 and covers Spring Boot and Spring 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

61. In Spring Boot, which annotation is used to create asynchronous methods?

a) @Async
b) @Scheduled
c) @EnableAsync
d) @AsyncMethod

Answer:

a) @Async

Explanation:

The @Async annotation in Spring Boot is used to indicate that a method should run asynchronously. It can be applied to methods that need to be executed in a separate thread.

62. What is the primary purpose of the @EnableJpaAuditing annotation in Spring Boot?

a) To enable JPA repository support
b) To configure application security
c) To enable auditing in JPA entities
d) To enable Aspect-Oriented Programming

Answer:

c) To enable auditing in JPA entities

Explanation:

The @EnableJpaAuditing annotation in Spring Boot enables JPA Auditing. It allows for the automatic population of audit-related fields in JPA entities, such as creation and modification dates.

63. How does Spring Boot support OAuth2 for securing applications?

a) By using the spring-boot-starter-oauth2-client dependency
b) Through the manual configuration of OAuth2 providers
c) By requiring a separate authentication server
d) Through XML configuration

Answer:

a) By using the spring-boot-starter-oauth2-client dependency

Explanation:

Spring Boot supports OAuth2 for securing applications by providing the spring-boot-starter-oauth2-client dependency. It simplifies the integration with OAuth2 providers for authentication and authorization.

64. In Spring Boot, what is the purpose of the @ExceptionHandler annotation?

a) To handle exceptions within a specific controller
b) To configure application security
c) To define scheduled tasks
d) To enable Aspect-Oriented Programming

Answer:

a) To handle exceptions within a specific controller

Explanation:

The @ExceptionHandler annotation in Spring Boot is used within a controller to define methods for handling specific exceptions thrown during executing controller methods.

65. What is the primary use of the @Transactional annotation in Spring Boot?

a) To enable batch processing
b) To configure application properties
c) To manage transactions declaratively
d) To enable WebSocket functionality

Answer:

c) To manage transactions declaratively

Explanation:

The @Transactional annotation in Spring Boot is used to manage transactions declaratively. It can be applied to classes or methods to define the scope of a transactional operation.

66. How does Spring Boot simplify the deployment of web applications?

a) By requiring a dedicated application server
b) By embedding servlet containers like Tomcat or Jetty
c) Through manual configuration of deployment settings
d) By using a specialized deployment tool

Answer:

b) By embedding servlet containers like Tomcat or Jetty

Explanation:

Spring Boot simplifies the deployment of web applications by embedding servlet containers like Tomcat, Jetty, or Undertow. This allows Spring Boot applications to run as standalone jars without needing an external server.

67. What is the primary role of the @RestController annotation in Spring Boot?

a) To define a scheduled task
b) To create a batch job
c) To define a web controller that returns a RESTful web service
d) To enable WebSocket functionality

Answer:

c) To define a web controller that returns a RESTful web service

Explanation:

The @RestController annotation is used in Spring Boot to create RESTful web services. It is a convenient annotation that combines @Controller and @ResponseBody and ensures that data returned by each method is written straight into the response body.

68. How does Spring Boot simplify the development of web applications?

a) By automatically configuring Spring MVC
b) By requiring manual configuration for each web component
c) By integrating third-party web frameworks
d) By using a purely annotation-based approach

Answer:

a) By automatically configuring Spring MVC

Explanation:

Spring Boot simplifies the development of web applications by auto-configuring Spring MVC, which reduces the need to specify configuration settings manually.

69. What is the function of the @RequestMapping annotation in Spring Boot?

a) To define a scheduler
b) To map web requests to handler methods in controller classes
c) To manage transactions
d) To configure security settings

Answer:

b) To map web requests to handler methods in controller classes

Explanation:

The @RequestMapping annotation is used to map web requests to handler methods in controller classes. It can be used for any HTTP method and supports advanced configuration options.

70. What is the purpose of the @ResponseBody annotation in a Spring Boot controller?

a) To bind method parameters to named model attributes
b) To enable WebSocket functionality
c) To send the returned object as the response body
d) To handle form submissions

Answer:

c) To send the returned object as the response body

Explanation:

The @ResponseBody annotation indicates that the return value of a controller method should be used as the request's response body.


Comments