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!

Q91

Q91 An application throws "NoClassDefFoundError" during startup. What is the likely cause?

A

Missing dependency

B

Incorrect classpath configuration

C

Corrupted JAR file

D

All of the above

Q92

Q92 What is the primary goal of Spring Security?

A

To provide authentication and authorization

B

To handle database transactions

C

To secure network communication

D

To provide MVC support

Q93

Q93 Which annotation is used to enable Spring Security configuration?

A

@EnableWebSecurity

B

@EnableSecurity

C

@EnableAuthorization

D

@EnableConfiguration

Q94

Q94 What is the default password storage mechanism in Spring Security?

A

MD5

B

SHA-256

C

BCrypt

D

Plain Text

Q95

Q95 How can you secure a REST API endpoint in Spring Security?

A

Use @Secure annotation

B

Use @PreAuthorize annotation

C

Use URL-based security

D

All of the above

Q96

Q96 How does Spring Security handle CSRF (Cross-Site Request Forgery)?

A

Enables by default

B

Disables by default

C

Requires custom filter

D

Not supported

Q97

Q97 How can you define a custom UserDetailsService in Spring Security?

A

Implement the UserDetailsService interface

B

Use the @Service annotation

C

Extend the UserDetails class

D

Use the AuthenticationManager interface

Q98

Q98 How can you configure HTTP security in Spring Security?

A

Use HttpSecurity in a configuration class

B

Use XML configuration

C

Use the @Secure annotation

D

Use the @Configuration annotation

Q99

Q99 An application throws "AccessDeniedException" in Spring Security. What is the likely cause?

A

Incorrect role configuration

B

Authentication failure

C

Improper password hashing

D

Invalid session configuration

Q100

Q100 Why does a "BadCredentialsException" occur in Spring Security?

A

Invalid username

B

Invalid password

C

Incorrect authentication provider configuration

D

All of the above

Q101

Q101 An application fails with "AuthenticationCredentialsNotFoundException". What could be the issue?

A

Missing authentication filter

B

Improper authentication manager configuration

C

No security context set

D

Any of the above

Q102

Q102 Which annotation is used to define a RESTful web service in Spring?

A

@RestController

B

@Controller

C

@RequestMapping

D

@Service

Q103

Q103 How does Spring handle serialization for REST responses?

A

Using ObjectMapper

B

Using SerializationUtils

C

Using custom serializers

D

Using built-in converters

Q104

Q104 What is the role of @ResponseBody in Spring REST?

A

Converts Java object to HTTP response body

B

Defines REST endpoints

C

Maps URLs to controllers

D

Handles dependency injection

Q105

Q105 How does Spring support content negotiation in REST APIs?

A

Using @RestController

B

Using MediaType class

C

Using @ResponseBody

D

Using Accept header

Q106

Q106 How can you define a GET endpoint in Spring REST?

A

Use @PostMapping

B

Use @PutMapping

C

Use @GetMapping

D

Use @DeleteMapping

Q107

Q107 How do you return a custom HTTP status in a Spring REST controller?

A

Use ResponseEntity

B

Use HttpHeaders

C

Use @ResponseBody

D

Use RestTemplate

Q108

Q108 How can you add query parameters to a REST endpoint in Spring?

A

Use @PathVariable

B

Use @RequestParam

C

Use @ModelAttribute

D

Use @RequestBody

Q109

Q109 Why does a "HttpMessageNotReadableException" occur in Spring REST?

A

Missing @RequestBody

B

Unsupported media type

C

Malformed JSON request

D

Improper dependency injection

Q110

Q110 An application fails with "HttpMediaTypeNotAcceptableException". What could be the issue?

A

Unsupported response media type

B

Invalid Accept header

C

Missing content negotiation strategy

D

All of the above

Q111

Q111 Which Spring module is typically used for unit testing?

A

Spring Test module

B

Spring Core module

C

Spring ORM module

D

Spring MVC module

Q112

Q112 How does Spring enable integration testing?

A

By providing in-memory database support

B

By offering testing annotations

C

By enabling mock injection

D

By using all these methods

Q113

Q113 What is the role of @ContextConfiguration in Spring tests?

A

Configures application context

B

Defines transactional boundaries

C

Sets up mock Beans

D

Enables AOP

Q114

Q114 Which annotation is used for transactional tests in Spring?

A

@Transactional

B

@TransactionTest

C

@IntegrationTest

D

@ContextConfiguration

Q115

Q115 How can you mock a Bean in Spring integration tests?

A

Use @MockBean annotation

B

Use @Mock annotation

C

Use @MockConfiguration

D

Use @BeanDefinition

Q116

Q116 How can you load a specific application context configuration in a test?

A

Use @ContextConfiguration annotation

B

Use @SpringConfiguration annotation

C

Use @Configuration annotation

D

Use @SpringTest annotation

Q117

Q117 How do you assert that a REST endpoint returns the correct status code?

A

Use MockMvc.perform()

B

Use ResponseEntity assertions

C

Use HttpClient assertions

D

Use RestTemplate

Q118

Q118 Why does a "BeanCreationException" occur in Spring tests?

A

Circular dependency

B

Missing Bean definition

C

Improper test configuration

D

All of the above

Q119

Q119 An integration test fails with "TransactionRollbackException". What is the likely cause?

A

Improper transactional boundary

B

Database constraint violation

C

Missing test configuration

D

Invalid mock data

Q120

Q120 What is the purpose of Spring Cloud?

A

To manage microservices

B

To secure web applications

C

To simplify testing

D

To enhance MVC features

ad verticalad vertical
ad