Spring Boot MCQ Questions and Answers | Set 5


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

41. What is the primary use of the @Repository annotation in Spring Boot?

a) To define a REST controller
b) To mark a class as a repository, indicating database interaction
c) To create scheduled tasks
d) To configure application properties

Answer:

b) To mark a class as a repository, indicating database interaction

Explanation:

The @Repository annotation in Spring Boot is used to mark a class as a repository, which indicates that it's responsible for data access and interactions with the database.

42. In Spring Boot, what is the purpose of the spring-boot-starter-jdbc dependency?

a) To provide JDBC (Java Database Connectivity) support
b) To support Java Messaging Service (JMS)
c) To enable Spring Security features
d) To integrate with Apache Kafka

Answer:

a) To provide JDBC (Java Database Connectivity) support

Explanation:

The spring-boot-starter-jdbc starter includes dependencies for using JDBC with Spring Boot, simplifying database access and operations using JDBC.

43. What is the purpose of the spring-boot-starter-aop dependency?

a) To provide support for Aspect-Oriented Programming
b) To enable RESTful web services
c) To add WebSocket communication capabilities
d) To provide batch processing functionalities

Answer:

a) To provide support for Aspect-Oriented Programming

Explanation:

The spring-boot-starter-aop starter includes dependencies for Aspect-Oriented Programming (AOP), enabling developers to implement cross-cutting concerns such as logging and transaction management.

44. What is the primary role of the spring-boot-starter-cache dependency?

a) To support caching abstraction in Spring Boot applications
b) To provide email-sending capabilities
c) To enable WebSocket communication
d) To offer batch processing functionalities

Answer:

a) To support caching abstraction in Spring Boot applications

Explanation:

The spring-boot-starter-cache starter provides support for caching abstraction in Spring Boot applications. It simplifies the integration of caching solutions like EhCache, Hazelcast, or Caffeine.

45. How can you handle exceptions globally in a Spring Boot application?

a) By using the @ControllerAdvice annotation
b) Through individual try-catch blocks in each method
c) By configuring a global error handler in application.properties
d) By deploying a separate error handling service

Answer:

a) By using the @ControllerAdvice annotation

Explanation:

The @ControllerAdvice annotation in Spring Boot handles exceptions globally across multiple controllers, allowing for centralized exception handling in a Spring Boot application.

46. What is the main purpose of the @EnableJpaRepositories annotation in Spring Boot?

a) To enable JPA repository support
b) To configure Spring Security
c) To define scheduled tasks
d) To enable Aspect-Oriented Programming

Answer:

a) To enable JPA repository support

Explanation:

The @EnableJpaRepositories annotation in Spring Boot is used to enable JPA repository support, allowing Spring to scan for JPA repository interfaces and create proxy implementations.

47. What is the role of the @Valid annotation in Spring Boot?

a) To ensure data validation in controller methods
b) To validate application properties
c) To validate SQL queries
d) To check the syntax of Java code

Answer:

a) To ensure data validation in controller methods

Explanation:

The @Valid annotation in Spring Boot is used in controller methods to ensure that data passed to the method is valid, often used in combination with Java Bean Validation API.

48. How is internationalization (i18n) typically implemented in Spring Boot?

a) By using a dedicated internationalization service
b) Through properties files for different locales
c) By hardcoding strings in the Java code
d) Using an external translation API

Answer:

b) Through properties files for different locales

Explanation:

Internationalization in Spring Boot is typically implemented using properties files for different locales (e.g., messages_en.properties, messages_fr.properties). This allows for easy translation and localization of application messages.

49. What is the primary purpose of the @ModelAttribute annotation in a Spring Boot web application?

a) To bind method parameters to named model attributes
b) To define a RESTful endpoint
c) To configure application security
d) To define a scheduled task

Answer:

a) To bind method parameters to named model attributes

Explanation:

The @ModelAttribute annotation in Spring Boot is used in controller methods to bind method parameters to named model attributes, often used in form submission handling.

50. In Spring Boot, which starter dependency is typically used for developing web applications with Thymeleaf templates?

a) spring-boot-starter-thymeleaf
b) spring-boot-starter-web
c) spring-boot-starter-jdbc
d) spring-boot-starter-freemarker

Answer:

a) spring-boot-starter-thymeleaf

Explanation:

The spring-boot-starter-thymeleaf starter is used to develop web applications with Thymeleaf templates. It provides integration with the Thymeleaf templating engine for building dynamic web pages.



Comments