Spring MCQ Banner

Spring Multiple Choice Questions (MCQs) and Answers

Master Spring Framework with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of Spring concepts. Begin your placement preparation journey now!

Q61

Q61 How can you configure a DataSource Bean in Spring?

A

Using @DataSource annotation

B

Using @Bean annotation in a configuration class

C

Using XML configuration

D

Using @Repository annotation

Q62

Q62 How do you define a repository interface in Spring Data JPA?

A

Extend the JpaRepository interface

B

Implement the JpaRepository interface

C

Extend the Repository class

D

Annotate it with @Transactional

Q63

Q63 How can you execute a named query in Spring Data JPA?

A

Use @Query annotation

B

Use EntityManager's createQuery method

C

Define a query in XML

D

Use @Transaction

Q64

Q64 How can you implement batch processing in Spring JDBC?

A

Use JdbcTemplate's batchUpdate method

B

Use @Batch annotation

C

Use @Transaction annotation

D

Use SQL scripts

Q65

Q65 An application fails with "DataIntegrityViolationException". What could be the cause?

A

Circular dependency

B

Database constraint violation

C

Incorrect Bean definition

D

Improper transaction management

Q66

Q66 Why does a "LazyInitializationException" occur in Spring Data JPA?

A

EntityManager closed prematurely

B

Incorrect database configuration

C

Improper dependency injection

D

Incorrect query syntax

Q67

Q67 An application throws "TransactionSystemException". What should you check?

A

Transaction timeout settings

B

Incorrect repository configuration

C

Database connection pool size

D

All of the above

Q68

Q68 What does MVC stand for in Spring?

A

Model View Controller

B

Model View Configuration

C

Model Value Controller

D

Mapping View Configuration

Q69

Q69 Which component of Spring MVC handles incoming HTTP requests?

A

DispatcherServlet

B

HandlerMapping

C

ViewResolver

D

ModelAndView

Q70

Q70 What is the role of ViewResolver in Spring MVC?

A

Resolves HTTP requests

B

Handles dependency injection

C

Maps views to names

D

Manages session state

Q71

Q71 How does Spring MVC handle form submissions?

A

By using @Controller

B

By mapping @RequestMapping

C

By using @ModelAttribute

D

By using all three

Q72

Q72 Which annotation is used to define a RESTful controller in Spring MVC?

A

@RestController

B

@Controller

C

@RequestMapping

D

@Service

Q73

Q73 How can you map a URL to a method in Spring MVC?

A

Use @Controller

B

Use @RestController

C

Use @RequestMapping

D

Use @Service

Q74

Q74 How do you pass data from a controller to a view in Spring MVC?

A

Use ModelAndView object

B

Use HttpServletResponse

C

Use DispatcherServlet

D

Use RestTemplate

Q75

Q75 How can you enable Spring MVC configuration in a Java-based configuration?

A

Use @EnableWebMvc annotation

B

Use @Configuration annotation

C

Use @Controller annotation

D

Use @RequestMapping annotation

Q76

Q76 How do you handle exceptions globally in Spring MVC?

A

Use @ExceptionHandler annotation

B

Use @ControllerAdvice annotation

C

Use global exception configuration

D

Use any one of the above

Q77

Q77 An application throws "404 Not Found" in Spring MVC. What is the likely cause?

A

Incorrect view name

B

Handler method not mapped

C

Invalid controller configuration

D

Missing @Controller annotation

Q78

Q78 Why does a "HttpMediaTypeNotSupportedException" occur in Spring MVC?

A

Unsupported content type

B

Missing view configuration

C

Invalid HTTP method

D

Incorrect controller mapping

Q79

Q79 An application fails with "NullPointerException" in a controller method. What could be the issue?

A

Missing @RequestParam annotation

B

Improper dependency injection

C

Invalid Bean configuration

D

All of the above

Q80

Q80 What is the purpose of Spring Boot?

A

To replace Spring Framework

B

To simplify Spring configuration

C

To handle database transactions

D

To build mobile apps

Q81

Q81 Which annotation is used to specify a Spring Boot application entry point?

A

@Configuration

B

@SpringBootApplication

C

@Component

D

@RestController

Q82

Q82 How does Spring Boot manage dependencies?

A

Using a custom Maven plugin

B

Using a built-in dependency manager

C

Using Maven's dependency scope

D

Using Spring Framework

Q83

Q83 What is the purpose of the application.properties file in Spring Boot?

A

To store application configuration

B

To store Bean definitions

C

To handle HTTP requests

D

To define security rules

Q84

Q84 What is the purpose of the @EnableAutoConfiguration annotation?

A

To enable custom configurations

B

To disable default configurations

C

To allow Spring Boot to guess configurations

D

To set application properties

Q85

Q85 How can you run a Spring Boot application from the command line?

A

Use the java command

B

Use mvn spring-boot:run

C

Use Gradle bootRun

D

Use mvn spring-run

Q86

Q86 How can you specify a custom port for a Spring Boot application?

A

Use server.port in application.properties

B

Use server.port in application.yml

C

Pass as a command-line argument

D

All of the above

Q87

Q87 How can you include additional libraries in a Spring Boot project?

A

Add to the classpath

B

Add to application.properties

C

Include in Maven's dependencies

D

Include in src/main/resources

Q88

Q88 How can you create a REST endpoint in Spring Boot?

A

Use @RestController annotation

B

Use @Component annotation

C

Use @RequestMapping annotation

D

Use @Service annotation

Q89

Q89 Why does a Spring Boot application fail to start with "Port already in use"?

A

Duplicate Bean definition

B

Invalid application.properties file

C

Another process is using the port

D

Dependency injection issue

Q90

Q90 Why does a "BeanCreationException" occur in Spring Boot?

A

Missing Bean configuration

B

Invalid dependency injection

C

Circular dependencies

D

All of the above

ad verticalad vertical
ad